Saturday 15 April 2017

View MTF (SFR) curves in the GUI

The Easter bunny has delivered. That most elusive of egg-laying mammals has brought you a new GUI feature, which finally completes the feature set I originally envisioned for MTF Mapper.

To visualize the MTF curve (or SFR curve, if you prefer), load up any suitable image in MTF Mapper using the menu option "File -> Open". Select the "Annotated image" output mode, like so:
Make sure "Annotated image" is selected in the desired output types box
You may select any of the other output types (e.g., "Grid") concurrently, except the "Focus position" output type, which is not currently compatible with the other output types.

Click the "Open" button, and wait for the outputs to start appearing in the "Data set" tree-view panel. Expand the entry in the tree-view to expose the "annotated" entry, and click on it:
Note the cyan-coloured text superimposed on the edges of your black target squares. These values are the MTF50 values of the edges, expressed in cycles per pixel.
Those cyan-coloured text labels serve two purposes: a) they tell you the MTF50 (cycles per pixel) of the edge on top of which it is drawn, and b) they are clickable (left mouse button) targets to bring up the MTF curve display for the selected edge.

A brief digression: If the text label is displayed in yellow (rather than cyan), then it indicates that MTF Mapper has deemed the edge to be of "medium" quality. This usually means that the edge orientation is poor, that is, close to one of the critical angles that could mean the displayed MTF50 value is less accurate than the ideal. The edge will also be displayed in yellow if the edge length is sub-optimal (meaning too few pixels along the edge), which also degrades the MTF accuracy. Normally the values displayed in yellow are still usable, but be careful.

Occasionally you will see some of the MTF50 labels displayed in red, like in this example:
The leftmost red label coincides with an edge with a ~25 degree orientation, which is within 2 degrees of the critical angle at 26.565 degrees
It is possible that an edge labelled in red is still usable, but there is no way to know for certain. I would rather recommend that you try to re-align your camera so that no edges end up with red labels, or that you ignore the edges with red labels for any serious analysis.

Back to the main story: clicking on an edge label pops up the MTF curve display window,
The result of a single left-button click on an MTF50 label
I hope the plot is self-explanatory. It corresponds to the MTF curve plots found in other slanted edge tools (Imatest, QuickMTF, ImageJ slanted edge plugin, etc.), with the x-axis of the plot indicating spatial frequency in cycles per pixel, and the y-axis indicating the contrast at the indicated frequency. In the top-right corner you can see a tag "MTF50=0.087" in a shade of blue that matches the plotted curve; this indicates the MTF50 value of the edge you just clicked on, as you might have expected.

The vertical gray bar is a cursor that follows the mouse, which will read off the actual contrast value corresponding to the MTF curve at the indicated spatial frequency; the read-out of this cursor is displayed just below the plot ("frequency: 0.098 contrast: 0.403" in the example). Again, the colour of the "contrast: <xyz>" readout matches that of the plotted curve.

While the MTF curve window is open, you may left-click on any other edge in the "annotated" image to replace the contents of the MTF curve window with the data corresponding to the newly selected edge. This includes clicking on edges in any other "annotated" output available in the "Data set" tree-view.

If you would like to compare the MTF curves of two edges, select the first edge as above, but hold down <shift> while left-clicking on the second edge. This adds the second edge to the plot:
Note the addition of the green curve, and the two green text labels, corresponding to the newly added edge's MTF
The read-out below the plot tracks and displays the MTF for both curves at the current spatial frequency, making it easy to read off accurate values for comparison purposes. Note that you can again select the second edge from any other "annoted" output in the "Data set" tree-view, making it easy to compare curves from different lenses or cameras.

Lastly, you can add a third curve to the plot using the same <shitf>+left click method.
Adding a third curve behaves as expected

If you already have three curves plotted, the last curve is replaced by this action. If you left click on a new edge without holding down shift, the plot reverts back to displaying only a single MTF curve (using the newly selected edge's MTF).

Update (2017/04/16)

I have since added the two save buttons, grab a copy of version 0.5.19 or later to give it a try.

Future improvements

It might be useful to drop a pin, or some other visual marker onto the "annotated" image to indicate which edge was selected. It might be even more useful to show the actual ROI used by MTF Mapper, but that information is not currently available in the outputs.

Let me know if you have any other suggestions for useful features to add to the MTF curve display function.

Where?

This feature is available from MTF Mapper 0.5.18 onwards, available from SourceForge.

2 comments:

  1. Is there a way to access the score used to create the annotation color or some other parameter from the command line? I know I can grab an annotated edge image and look for the color. I am scoring individual edges. Ralph

    ReplyDelete
  2. Hi Ralph,

    Unfortunately the "edge quality" value is not recorded in any of existing text output files (such as edge_mtf_values.txt), and I have to maintain backwards compatibility for those outputs.

    What you can do, though, is to look at the MTF50 value in the edge_mtf_values.txt file (see section 5.6 of the user guide). If this value is 1.0 cycles/pixel, then the edge will have been coloured red (possibly marked as "N/A") in the annotated output.

    The edge will be coloured yellow in the annotated output if the edge is shorter than 25 pixels, which you might be able to infer from your image dimensions if you are processing individual edges with the --single-roi option. If by "scoring individual edges" you meant that you still process a whole chart, then you can infer the size of the squares from the edge centroids (second and third columns in edge_mtf_values.txt, see chapter 5.6 of the user guide). I would recommend that you use larger edges if possible, if you regularly end up with such short edges.

    The last condition that would produce a yellow annotation would be if the relative edge angle was close to 26.565 degrees; in the code I check for closer than 1 degree to 26.565. You can extract the relative edge angle as column 4 in edge_sfr_values.txt.

    There are two more angle checks that produce a red annotation: relative angles below 1 degree, and above 44 degrees. These do not typically produce a N/A.

    If I may ask, what do you want to do with the edge quality score?

    ReplyDelete