I'm using MTF Mapper gui and I like the efficiency of the software comparing to other tool !
I would like to make it even more easier for my purpose.
I'm analysing a Camera and I'm looking for the resolution at 100lp/mm. With the "User manuals for individual application" I was wondering if it was possible to write a script that can give me this value only by ginving him an Image and the size of the pixel (without looking to all the curve).
I know my question will seems basic, but I am a beginner even for coding I didn't understand where and how can I use the mtf_mapper.exe. On Python ? And the options ? I am lacking of example for that purpose and I would enjoy to have one to understand more.
Sorry again for bothering and thanks for all the work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Let's assume that you have mtf_mapper.exe on your PATH (see this tutorial, and you have a cmd.exe window open (or powershell). Let's also assume you have a file called sample.png (I attached one) in the current directory.
Then you can run the command
mtf_mapper -v 2 -q sample.png .
which will produce an output file called edge_sfr_values.txt in the current directory. This file contains some comments, i.e., lines starting with a "#" symbol, which describe the meaning of the different columns in the rest of the file. The columns are separated by spaces, by the way. When you process this file in Python (or some other scripting language), you can simply ignore all the lines that start with "#", and read the entire contents of all the other lines.
The SFR curve that you need will be stored in columns 14 through 77 inclusive, and represents the contrast at spatial frequency. I would recommend that you extract these columns into an array called SFR so that SFR[0] refers to the value found in column 14, and SFR[6] refers to the value in column 77. In general, SFR[i] refers to the value found in column i + 14.
You say that you are interested in the contrast at a spatial frequency of 100 lp/mm. This corresponds to the value at SFR[f] where f = pixel_size_micron * 100 * 64 / 1000. The "100" refers to the desired lp/mm, the 64 is a scaling constant, and the division by 1000 is to convert the pixel size in micron to a pixel size in mm.
The problem is now that f is a real number, most likely with a non-zero fractional part. The solution is to round f down to obtain g = floor(f). Now compute the fractional part as h = f - g. Finally, you can compute SFR[f] = SFR[g] * (1 - h) + SFR[g+1] * h
The above is just a simple linear interpolation between the two values in the SFR[] array that are closest to the real-valued frequency f.
So that's how you would calculate the contrast at a frequency of 100 lp/mm using the output of MTF Mapper, without using the GUI.
There's a lot of other details here, such as
1. The process described above applies to a single edge, however, the edge_sfr_values.txt file contains a line for each edge that MTF Mapper processed. You would perform the calculation above for each edge / output line in the file.
2. The harder part is associating each line of edge_sfr_values.txt with an actual edge in the image. MTF Mapper gives you the pixel coordinates of the centroid of each edge (columns 2 and 3 of sfr_edge_values.txt), but this does not help you much unless you want to either process all the edges, or have only 4 or so edges in your input image.
I realise that this does not directly help you to automate the extraction of the information you need, but my suggestion would be to enlist the help of someone who can implement the above steps in a Python script for you. My own attempt at making this step user-friendly is the MTF Mapper GUI itself :)
I'd be happy to answer more questions if you have any.
Sorry for answering this late, I put my project aside for a bit.
Thank you so much for answering my message. Even if I am a beginner, I have succeeded to reach my aim thanks to your help.
Thank you again for your work.
I wish you well
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm using MTF Mapper gui and I like the efficiency of the software comparing to other tool !
I would like to make it even more easier for my purpose.
I'm analysing a Camera and I'm looking for the resolution at 100lp/mm. With the "User manuals for individual application" I was wondering if it was possible to write a script that can give me this value only by ginving him an Image and the size of the pixel (without looking to all the curve).
I know my question will seems basic, but I am a beginner even for coding I didn't understand where and how can I use the mtf_mapper.exe. On Python ? And the options ? I am lacking of example for that purpose and I would enjoy to have one to understand more.
Sorry again for bothering and thanks for all the work.
Hi!
Yes, this is certainly possible.
Let's assume that you have mtf_mapper.exe on your PATH (see this tutorial, and you have a cmd.exe window open (or powershell). Let's also assume you have a file called sample.png (I attached one) in the current directory.
Then you can run the command
which will produce an output file called edge_sfr_values.txt in the current directory. This file contains some comments, i.e., lines starting with a "#" symbol, which describe the meaning of the different columns in the rest of the file. The columns are separated by spaces, by the way. When you process this file in Python (or some other scripting language), you can simply ignore all the lines that start with "#", and read the entire contents of all the other lines.
The SFR curve that you need will be stored in columns 14 through 77 inclusive, and represents the contrast at spatial frequency. I would recommend that you extract these columns into an array called SFR so that
SFR[0]refers to the value found in column 14, andSFR[6]refers to the value in column 77. In general,SFR[i]refers to the value found in column i + 14.You say that you are interested in the contrast at a spatial frequency of 100 lp/mm. This corresponds to the value at
SFR[f]where f = pixel_size_micron * 100 * 64 / 1000. The "100" refers to the desired lp/mm, the 64 is a scaling constant, and the division by 1000 is to convert the pixel size in micron to a pixel size in mm.The problem is now that f is a real number, most likely with a non-zero fractional part. The solution is to round f down to obtain g = floor(f). Now compute the fractional part as h = f - g. Finally, you can compute
SFR[f] = SFR[g] * (1 - h) + SFR[g+1] * hThe above is just a simple linear interpolation between the two values in the
SFR[]array that are closest to the real-valued frequency f.So that's how you would calculate the contrast at a frequency of 100 lp/mm using the output of MTF Mapper, without using the GUI.
There's a lot of other details here, such as
1. The process described above applies to a single edge, however, the edge_sfr_values.txt file contains a line for each edge that MTF Mapper processed. You would perform the calculation above for each edge / output line in the file.
2. The harder part is associating each line of edge_sfr_values.txt with an actual edge in the image. MTF Mapper gives you the pixel coordinates of the centroid of each edge (columns 2 and 3 of sfr_edge_values.txt), but this does not help you much unless you want to either process all the edges, or have only 4 or so edges in your input image.
I realise that this does not directly help you to automate the extraction of the information you need, but my suggestion would be to enlist the help of someone who can implement the above steps in a Python script for you. My own attempt at making this step user-friendly is the MTF Mapper GUI itself :)
I'd be happy to answer more questions if you have any.
Regards,
Frans
Hi,
Sorry for answering this late, I put my project aside for a bit.
Thank you so much for answering my message. Even if I am a beginner, I have succeeded to reach my aim thanks to your help.
Thank you again for your work.
I wish you well