Leica M9 CAL and M9 FIX Software for out-of-calibration M9 Sensors

Sonnar Brian

Product of the Fifties
Staff member
Local time
12:54 PM
Joined
Jan 12, 2004
Messages
19,778
Leica no longer replaces the CCD sensor used in the Leica M9 series and M Monochrom.
Third Party repair shops will replace the cover glass used for these cameras.
The CCD array in the M9P, M Monochrom, and (likely) M-E use a cement that is different
from the original M9. At this point, only one repair facility will replace the cover
glass on these cameras.

This repair can introduce problems with the calibration of the left vs right side
of the sensor array. The KAF-18500 uses separate calibrations for the two halves
of the array. The process of replacing the cover glass can affect the calibration.
This problem manifests itself in the image as one side being darker than the other.

Two programs are provided here to correct this problem:
1) M9CAL: generate coefficients to align the left half of the image with the right
2) M9FIX: use the coefficients to correct the error.

The programs work only with uncompressed DNG files as produced by the camera.
The file sizes are:
M9: 36,433,920 Bytes
MM: 36,433,408 Bytes

The program works with the Image File as saved by the camera, Photoshop and other
programs change this original file when saving it. Lightroom does not change the file.

M9CAL:
This program is used to generate the calibration coefficients. The Serial Number of the
camera is detected in the DNG file and used to name the calibration once is it generated.
M9CAL will also make the "C:\M9CAL" directory when it is run. M9CAL will store calibration
files in this directory.

The user must make a set of 5 images to perform the calibration. It is recommended to
use an 18% grey card for this, but any uniform image will work.
Five files are required to produce the calibration:
M2.DNG: -2ev Exposure
M1.DNG: -1ev Exposure
P0.DNG: correct Exposure
P1.DNG: +1ev Exposure
P2.DNG: +2ev Exposure

M9CAL reads these files in, performs an 8x8 average over the image, and selects the
center values on each side of the KAF-18500 to generate a linear fit. This is a simple
Y= X* Slope+ Intercept calculation. A Least Squares Fit routine is used. Use the CMD prompt
to change to the directory that these 5 files are stored, run the program.
Assuming M9CAL is stored in directory "C:\M9CAL", type
C:\M9CAL\M9CAL
to run the program.
You will get messages to the screen as the files are parsed and processed.

Program M9FIX is used to apply the calibration to the DNG files from the camera.
The program uses a minimum of input, asks for a Filename. The user may input a specific
file to apply the correction. Hitting "enter" without giving a filename results in M9FIX
spawning a "DIR L???????.DNG" command to get all files in the directory. M9FIX then
runs the correction for all DNG files as named by the camera. The Serial Number from the
DNG file is used to select the correct calibration generated previously and stored in
"C:\M9CAL". Files from the M9 and M Monochrom may be in the same directory, M9FIX uses
metadata stored in the DNG file to determine camera type and serial number.

The "Command Line Prompt" is invoked by typing "cmd" on the "type here to search" on the
Windows task bar. An old style "DOS Window" will open on the screen. M9CAL and M9FIX are
"Character Mode Executable" programs. One easy way to use them is to create the "M9CAL"
directory and store the .exe files there.

After typing "cmd", create the directory using:
MD C:\M9CAL

Now you want to download the two .EXE files to it.
M9CAL may be downloaded from this link (link updated 9/2024):


M9FIX may be downloaded from this link (link updated 9/2024):


Fortran-77 Source code for the Watcom Fortran V2 compiler is available:
Dropbox
Dropbox

The M9FIX code does not change the original file from the camera. Instead,
it creates a new version of the DNG file with a "C" as the first character
in the name. SO- if your original file is "L1000001.DNG" the new file will be
"C1000001.DNG". If your SD card is less than 1/2 full, this means you can run
the M9FIX program on the card. Insert it into the computer, find the Device Letter.
On my computer the SD card usually comes up as "I:". The DNG files are stored under
"DCIM\LEICA101" or something close to that. Use Windows Explorer to find the DNG files.
At the CMD prompt, change to the SD card and the correct directory using (for example),
I:
CD I:\DCIM\LEICA101

do a "DIR" to see your files.

Assuming the M9FIX program is in directory C:\M9CAL type in
C:\M9CAL\M9FIX

you will get a prompt,
FILE TO PROCESS:

Just hit enter without giving a name to process all files in the
directory.

You will see lots of messages coming to the screen. The coefficients,
serial number of the camera, and information found in the DNG file
that are written to the screen as M9FIX parses the file looking for
the image.
At the end, you should have new DNG files that start with a "C".
These open in Lightroom and Photoshop, I have not tested on others.
The DNG file header has not been altered, only the image data for the left
side of the sensor has been altered.

All software is "free and as is". I'm not putting that licensing stuff in it. Source code provided- so anyone can download the Watcom Fortran-77 V2 compiler and build it. No special setup required, it will complain that I declare some variables and so not use them. I started with code written long, long ago in a DOS galaxy that is Far, Far away from most people. But not for me.

This was about 20 hours of work- if anyone else wants to put a GUI, write their own from scratch looking at this code, or port to a MAC- feel free.
And I like upper case. Using Mixed-Case slows me down from writing code.

EDIT: One camera required calibration coefficients to be generated for ISO 160, 640, 1250, and 2500. The imbalance is a huge 10% on this camera at ISO 160 and about 8% at ISO2500. I ended pulling the ISO speed from the DNG file and using it to select the coefficients. I've not modified the M9CAL program to do this automatically.
 
Last edited:
Thankyou!

It's always nice to be able to use Programming Techniques that are 25 years out-of-date and solve a problem.
 
Well done, Brian. This was great work for another RFF member. Others can benefit from similar cases they may be facing or will be facing in the future.
 
So cool Brian. I never used Fortran but I'm curious, so will check out the source.

For anyone else, another way to simplify the usage even further is to add
C:\M9CAL\
(or whatever directory you put the programs in)

to you path file. You can do it through the GUI or the command line itself.

Shawn
 
You are al very welcome. I always enjoy writing image processing code- you get to see the results. Back in the 1980s, it was very new- proud to have been part of it. When I do a "details" for the directory of this "build", some of the files go back as far as 1986. I am "old School". Most of the code was made to run under DOS. Converting to run under Windows, "I am SO 21st Century, Baby!"
 
my first pic with M9P after Brian correction... I'm touched 😱



sorry, but I had to comunicate this to the community 😛
 
That looks good to me. I'm very happy to have been able to help.

I'll ask that you try out "M9FIX" with some files from each camera in the same directory. I used M9CAL to generate the two files provided to you.

You are my "Alpha Tester". Any problems- report back and we'll work them out.
 
That looks good to me. I'm very happy to have been able to help.

I'll ask that you try out "M9FIX" with some files from each camera in the same directory. I used M9CAL to generate the two files provided to you.

You are my "Alpha Tester". Any problems- report back and we'll work them out.

ok boss! 😀
 
ISO 1250 is where the M9 adds an analog gain, so it is something I asked Luuca to test. Luuca noted that ISO 1250 and ISO 2500 files were over-corrected on the M9 Grey body. There was a 3% difference in the coefficients- now corrected. The left and right side of this M9 were off by a huge 10% at low-ISO. The M9 Black body was less than 2%, did not need the second set of coefficients.

If anyone else runs into this problem- post to this thread. I have a version of the code that uses a test of the DNG file to switch coefficients. If enough people have a problem, I'll put it into the M9CAL and M9FIX code to use the second set of coefficients for High-ISO.

I need to find where the M9 stores the ISO value in the file. '7a4'x is the name of the Profile. It is stored in ASCII, but the ISO is not. At worst- take 5 images with the lens cap on, set the shutter speed to the same value- and look for the changes in the files. EDIT- I have this working now, found the location of the ISO setting in the DNG file. The camera that is 10% off: coefficients for ISO 160, 640, 1250, and 2500 were required. The 1250 gave me fits.
 
I found the location of the ISO setting in EXIF- '033a'x, Tag '8127'x.

A MUST READ for anyone wanting to write their own software to read M8 and M9 files.
https://bretteville.com/pdfs/M8Metadata_v2.pdf

The calibration of the camera that is far off changes with ISO. It also seems to "Drift"- a "little".

The M9 has a cover glass that is easily removed. The M9P and M Monochrom cover glass is attached differently, requires much more invasive techniques possible including heat. The max storage temperature of the KAF-18500 is 70C, the data sheet warns of color change if this is done long term. No mention of what happens if it is heated beyond 70C- but cannot be good.

If you send a camera in for service, please post results on this thread. If you run into problem, I can try to adapt the software to your camera.
 
Leica no longer replaces the CCD sensor used in the Leica M9 series and M Monochrom.
Third Party repair shops will replace the cover glass used for these cameras.
The CCD array in the M9P, M Monochrom, and (likely) M-E use a cement that is different
from the original M9. At this point, only one repair facility will replace the cover
glass on these cameras.

This repair can introduce problems with the calibration of the left vs right side
of the sensor array. The KAF-18500 uses separate calibrations for the two halves
of the array. The process of replacing the cover glass can affect the calibration.
This problem manifests itself in the image as one side being darker than the other.

Two programs are provided here to correct this problem:
1) M9CAL: generate coefficients to align the left half of the image with the right
2) M9FIX: use the coefficients to correct the error.

The programs work only with uncompressed DNG files as produced by the camera.
The file sizes are:
M9: 36,433,920 Bytes
MM: 36,433,408 Bytes

The program works with the Image File as saved by the camera, Photoshop and other
programs change this original file when saving it. Lightroom does not change the file.

M9CAL:
This program is used to generate the calibration coefficients. The Serial Number of the
camera is detected in the DNG file and used to name the calibration once is it generated.
M9CAL will also make the "C:\M9CAL" directory when it is run. M9CAL will store calibration
files in this directory.

The user must make a set of 5 images to perform the calibration. It is recommended to
use an 18% grey card for this, but any uniform image will work.
Five files are required to produce the calibration:
M2.DNG: -2ev Exposure
M1.DNG: -1ev Exposure
P0.DNG: correct Exposure
P1.DNG: +1ev Exposure
P2.DNG: +2ev Exposure

M9CAL reads these files in, performs an 8x8 average over the image, and selects the
center values on each side of the KAF-18500 to generate a linear fit. This is a simple
Y= X* Slope+ Intercept calculation. A Least Squares Fit routine is used. Use the CMD prompt
to change to the directory that these 5 files are stored, run the program.
Assuming M9CAL is stored in directory "C:\M9CAL", type
C:\M9CAL\M9CAL
to run the program.
You will get messages to the screen as the files are parsed and processed.

Program M9FIX is used to apply the calibration to the DNG files from the camera.
The program uses a minimum of input, asks for a Filename. The user may input a specific
file to apply the correction. Hitting "enter" without giving a filename results in M9FIX
spawning a "DIR L???????.DNG" command to get all files in the directory. M9FIX then
runs the correction for all DNG files as named by the camera. The Serial Number from the
DNG file is used to select the correct calibration generated previously and stored in
"C:\M9CAL". Files from the M9 and M Monochrom may be in the same directory, M9FIX uses
metadata stored in the DNG file to determine camera type and serial number.

The "Command Line Prompt" is invoked by typing "cmd" on the "type here to search" on the
Windows task bar. An old style "DOS Window" will open on the screen. M9CAL and M9FIX are
"Character Mode Executable" programs. One easy way to use them is to create the "M9CAL"
directory and store the .exe files there.

After typing "cmd", create the directory using:
MD C:\M9CAL

Now you want to download the two .EXE files to it.
M9CAL may be downloaded from this link:
Dropbox - File Deleted - Simplify your life

M9FIX may be downloaded from this link.
Dropbox - File Deleted - Simplify your life

Fortran-77 Source code for the Watcom Fortran V2 compiler is available:
Dropbox
Dropbox

The M9FIX code does not change the original file from the camera. Instead,
it creates a new version of the DNG file with a "C" as the first character
in the name. SO- if your original file is "L1000001.DNG" the new file will be
"C1000001.DNG". If your SD card is less than 1/2 full, this means you can run
the M9FIX program on the card. Insert it into the computer, find the Device Letter.
On my computer the SD card usually comes up as "I:". The DNG files are stored under
"DCIM\LEICA101" or something close to that. Use Windows Explorer to find the DNG files.
At the CMD prompt, change to the SD card and the correct directory using (for example),
I:
CD I:\DCIM\LEICA101

do a "DIR" to see your files.

Assuming the M9FIX program is in directory C:\M9CAL type in
C:\M9CAL\M9FIX

you will get a prompt,
FILE TO PROCESS:

Just hit enter without giving a name to process all files in the
directory.

You will see lots of messages coming to the screen. The coefficients,
serial number of the camera, and information found in the DNG file
that are written to the screen as M9FIX parses the file looking for
the image.
At the end, you should have new DNG files that start with a "C".
These open in Lightroom and Photoshop, I have not tested on others.
The DNG file header has not been altered, only the image data for the left
side of the sensor has been altered.

All software is "free and as is". I'm not putting that licensing stuff in it. Source code provided- so anyone can download the Watcom Fortran-77 V2 compiler and build it. No special setup required, it will complain that I declare some variables and so not use them. I started with code written long, long ago in a DOS galaxy that is Far, Far away from most people. But not for me.

This was about 20 hours of work- if anyone else wants to put a GUI, write their own from scratch looking at this code, or port to a MAC- feel free.
And I like upper case. Using Mixed-Case slows me down from writing code.

EDIT: One camera required calibration coefficients to be generated for ISO 160, 640, 1250, and 2500. The imbalance is a huge 10% on this camera at ISO 160 and about 8% at ISO2500. I ended pulling the ISO speed from the DNG file and using it to select the coefficients. I've not modified the M9CAL program to do this automatically. If anyone runs into this problem before I replace the current M9CAL, let me know. I plan on updating it.
Hello Brian

Recently, I sent my Leica m monochrom to a third party to replace the filter. After the replacement, my camera also had an imbalance problem between the left and right sides.

I'm very lucky to see your solution, but the file linked to the cloud has been deleted. Can you please re-upload it?

*I tried Fortran-77 Source code, but my computer can't run the program
 
Hello Brian

Recently, I sent my Leica m monochrom to a third party to replace the filter. After the replacement, my camera also had an imbalance problem between the left and right sides.

I'm very lucky to see your solution, but the file linked to the cloud has been deleted. Can you please re-upload it?

*I tried Fortran-77 Source code, but my computer can't run the program
It's been a couple of years since I looked at the code- but did find it. I need to make sure the versions are the latest. I'll log into Dropbox and put the .exe files back up.
You will need to generate a set of images to calibrate the CCD corrections. We also ran into an issue with different ISO values causing the two halves to require corrections for different ISO.
 
Last edited:
Hello Brian

Recently, I sent my Leica m monochrom to a third party to replace the filter. After the replacement, my camera also had an imbalance problem between the left and right sides.

I'm very lucky to see your solution, but the file linked to the cloud has been deleted. Can you please re-upload it?

*I tried Fortran-77 Source code, but my computer can't run the program
I found the compiled executables on one of my older computers- and uploaded them again.

M9CAL


M9FIX


These are Windows "console" programs.
Could you tell us who did the sensor repair for you? Not many people doing this.
 
在輸入搜尋」中輸入「cm
I found the compiled executables on one of my older computers- and uploaded them again.

M9CAL


M9FIX


These are Windows "console" programs.
Could you tell us who did the sensor repair for you? Not many people doing this.
Thank you very much for the program you provided. I will conduct tests later.

I will let you know the results after the tests.

I had the filter replaced in Taiwan.

After the replacement, I noticed a problem (imbalance between the left and right sides). I consulted a technician in Taiwan about the replacement process.

  • My filter was cracked, so I sent it for replacement. CCD ID: 51
Replacement method:

  1. Attach a piece of intact glass over the cracked filter on the camera.
  2. Use a non-continuous heating method to slowly remove it, which took about 3 days.
  3. Replace it with a new filter.
Currently, it is suspected that uneven aging of the CCD on the left and right sides was caused by the heat.
 
The Kodak CCD is comprised of two smaller CCDs which are abutted. The calibration for the two halves brings the image into agreement.
The type of filter glass was changed, which upsets the calibration.

Keep us posted on results.
 
Back
Top Bottom