Menu

mtf_generate_rectangle: usaf1951r.txt

Dean Goff
2024-11-22
2024-11-27
  • Dean Goff

    Dean Goff - 2024-11-22

    Hi, I've been using mtf_generate_rectangle to generate rectangles, but I'd like to generate more complex charts and see usaf1951r.txt mentioned in your blog. However, I cannot find this file in the distribution or on SourceForge and think it would act as a good starting point for my own charts. Can you supply this and the Siemens example? Thanks, Dean. PS I'm working on Windows.

     
    • Frans van den Bergh

      Hi Dean,

      I have attached a sample of the usaf1951r.txt file, but also included some AWK scripts for generating more such charts. I also found the siemens.txt file, so I included the scripts for generating more of these too.

      I know you mentioned that you are working on Windows, but with some kind of Windows-Subsystem-for-Linux (WSL) you might be able to run AWK. Otherwise, I'm sure you can try to ask ChatGPT to convert the AWK scripts into Python.

      Regardless, it is pretty simple to generate these input files: the siemens.txt example is a good place to start. If I remember correctly, each file is just a list of polygons, and each polygon just starts with a line containing the number of vertices, n, followed by n lines of x y coordinates, one for each vertex. I think the vertices must be given in the clockwise order. Polygons must have fewer than 400 vertices, so you will have to split complex shapes into multiple polygons if necessary.

      The mtf_generate_rectangle tool will automatically size the output image to cover the input polygons, so you are "drawing on the sensor", so to speak.

      I probably mentioned this in the blog post, but you will need a command like this,

      mtf_generate_rectangle --b16 -n 0 -p airy-box --aperture 8 --target-poly ./usaf1951r.txt -o test.png
      

      to actually generate the image.

       
  • Dean Goff

    Dean Goff - 2024-11-26

    Hi Frans, Thank you very much for this, as well as the ChatGPT tip, as I have struggled to get Gawk working on Windows. One further question... One of my aims is to replicate the work described in "Comparison of tilted slit and tilted edge supperresolution MTF techniques" by Olson et al. (2007). My plan is to create a narrow slit using the generator - do you think this will work? Thanks in advance, Dean.

     
    • Frans van den Bergh

      Hi Dean,

      I found the paper on Google scholar, but scholar did not find an open-access PDF, so I only have the abstract to go on. If I understand correctly (based on other similar papers) the idea is to use a slit instead of a point light source (too few photons, requires some magnification optics). The slit will have a rect() function impulse response across the narrow part of the slit, compared to the step() impulse response of the slanted-edge method. I suppose if you knew the width of the slit you could simply "divide out" the correctly scaled rect() function in the Fourier domain to obtain the MTF function. (just thinking out loud here)

      Anyway, the mtf_generare_rectangle tool accepts a custom photosite geometry which you could potentially abuse to simulate a slit. Normally, if you use a command like
      mtf_generate_rectangle --b16 -n 0 -p airy-box --aperture 8 --target-poly ./usaf1951r.txt -o usaf_plain.png
      you end up with a PSF that convolves the scene with a square polygon (nominally [[-0.5, -0.5], [0.5, -0.5], [0.5, 0.5], [-0.5, 0.5]]). That square polygon represents the aperture of the photosite.

      You can specify an arbitrary convex polygon, so you could increase the width of of the nominal square by a factor 10 (see attached photosite_slit.txt), which you would use like this:
      mtf_generate_rectangle --b16 -n 0 -p airy-box --aperture 8 --target-poly ./usaf1951r.txt -o usaf_slit.png --photosite-poly photosite_slit.txt

      It should also work if you use a rotated slit (not sure if that is required, since I cannot read the full paper you mentioned).

      The tricky part is that to simulate a real system you will have to calculate the required magnification so that the width of the slit matches the projection of the physical slit on the sensor. I also think this is a bit of a hack because I think what you need is the convolution of the square photosite aperture and the slit, rather than just replacing the photosite aperture with a rectangle. This is not something that mtf_generate_rectangle can do, though.

      Maybe I'm looking at it from the wrong direction: if you just want the impulse response of the slit, then just creating a slit using the --target-poly geometry will be sufficient (and leave the --photosite-poly options out). At smaller apertures (larger --aperture values) the PSF can be quite wide, so to avoid end-effects you should generate a rather tall slit geometry, and use the --roi-row, --roi-col, --roi-height and --roi-width options to crop out a reasonable image size. A rough guideline would be to generate the --target-poly geometry to be 3x taller than the image you need. Using the ROI commands is equivalent to rendering the full 3x taller image and cropping it afterwards, but quicker because you are rendering a smaller output image.

      Anyhow, hope I am thinking in the right direction here.

      Regards,
      Frans

       

      Last edit: Frans van den Bergh 2024-11-26
  • Dean Goff

    Dean Goff - 2024-11-27

    Hi Frans,
    Thanks again for your response. In the paper they convolve the slit with the presample blur of the sensor and then sample it. Having reread the paper I think this is what I need to do - I was hoping that mtf_generate_rectangle might offer a shortcut for doing this, but from your explanation above, I don't think that it will. I've attached the paper for your interest.
    Kind regards,
    Dean.

     

Log in to post a comment.

MongoDB Logo MongoDB