MTF_GENERATE_RECTANG(1)
β¨ MTF_GENERATE_RECTANG π β the mtf_generate_rectangle manual page β¨
okay bestie, sit DOWN, grab a strawberry matcha π, because we're about to talk about mtf_generate_rectangle(1) β your new fave little image-generating icon π
πΈ NAME πΈ
mtf_generate_rectangle β generate images containing edges with known MTF50 values. yes. it makes the edges. it tells you the MTF50. she's precise, she's iconic, she's literally the blueprint π
π¦ SYNOPSIS π¦
mtf_generate_rectangle [OPTIONS]
that's it. that's the whole vibe. options go in, pixels come out π
π DESCRIPTION π
okay so mtf_generate_rectangle renders an image β default name rect.png in case you were wondering π«Ά β containing a rectangle rotated through the specified angle. and it's not just rectangles either, other polygonal objects can be rendered too, she contains multitudes β¨
the image gets generated with a specified type of point spread function (PSF), which can either be:
- a simple Gaussian π
- or a diffraction pattern with an optional optical low-pass filter (OLPF) π
various parameters can be adjusted to produce the desired size / shape of the PSF, because customization is self-care π
sensor noise? simulated. using either:
- a simple additive Gaussian model, or
- a more sophisticated sensor noise model π
then β and this is the part that ATE β the program reports the analytical MTF50 value of the rendered edges. no cap.
so why do we care? bestie, mtf_generate_rectangle can be used to evaluate the accuracy of the mtf_mapper tool, since the accuracy of the images generated with mtf_generate_rectangle have been validated by third parties. third parties!! she's peer-reviewed, she's got receipts, she's fr fr trustworthy π
π OPTIONS π
--b16β render output image as a linear intensity 16-bit grayscale image. (default is 8 bits gamma corrected, if you were curious π¦)-lβ render output image as a linear grayscale image. (default is sRGB gamma, periodt)-dpixels β dimension of the long edge of the rectangle, in pixels. β οΈ please note that MTF Mapper may produce inaccurate results if this parameter is below 35 pixels. so like, don't. keep it 35 and up, bestie.-xpixels β sub-pixel offset applied to rendered rectangle, x-axis direction.-ypixels β sub-pixel offset applied to rendered rectangle, y-axis direction.-bstd. dev β specify the standard deviation of the Gaussian point spread function (PSF) with which the edges are sampled. this parameter effectively controls the resulting MTF50 value of the edges. π¨ mutually exclusive with-m. pick one, bestie, you can't have both.-mmtf50 β directly specify the desired MTF50 value. this indirectly controls the Gaussian PSF standard deviation. π¨ mutually exclusive with-b. (again. one or the other. choose your fighter π )-aangle β specify the angle (in degrees) at which the rectangle is generated. useful for characterising MTF measurement accuracy as a function of edge orientation π₯ (rotating? slay.)-rratio β specify the aspect ratio of the rectangle in the range[0,1]. ratios above1.0are clipped. the aspect ratio is adjusted so that the rectange is at least one pixel wide. (yes they wrote "rectange" in the original, we love her anyway π) very thin rectangles (< 25 pixels wide) are not ideal for use with MTF Mapper. so like, keep her fed and wide, okay?--esf-onlyβ render only a cross-section across the edge of the rectangle at a1/32thpixel spacing. this is mainly useful for performing synthetic image accuracy measurements, but can be used to generate Point Spread Functions (PSFs) for theboxand4dot-olpfAiry pattern variants β and those PSFs are hard to compute analytically, so this is genuinely helpful, ngl π«Ά. default output filename isprofile.txt, but can be specified with-o.-ofilename β specify the name of the output file. name her whatever you want, bestie β¨-hβ displays usage information. the classic. the icon. when in doubt,-hπ
π NOISE OPTIONS π
-nstd. dev β specify the noise standard deviation[0-1)of the Gaussian noise that is added to the image. this invokes the simplified noise model (which is also the default π), which produces noise that is independent of signal level. a more accurate sensor noise model can be obtained with the full sensor noise model (--read-noise, etc.); see examples below π--adc-depthbits β number of bits used in full noise model ADC. this parameter effectively scales photon shot noise π. recommended value is12.--adc-gainelectrons β number of electrons per DN, i.e., the ADC gain of the full noise model. recommended value is2.64β¨--pattern-noisefraction β magnitude of Pixel Response Non-Uniformity (PRNU) component of full noise model. recommended value is0.0085π--read-noisestd. dev β standard deviation of read noise component of full noise model, in electrons. recommended value is3.7β-cfactor β reduce edge contrast by factor, i.e., if factor is0.3, then the edge contrast is1 - 0.3 = 0.7. math!! she does it!! π§-sseed β specify the random seed for the RNG used to generate the additive Gaussian noise. π² reproducible chaos, we love to see it.
π PSF/RENDERING OPTIONS π
-pgaussian|gaussian-sampled|airy|airy-box|airy-4dot-olpf|wavefront|wavefront-boxβ specify the desired PSF type.
PSF types gaussian and gaussian-sampled accept the -m and -b arguments to control PSF shape, and produce, unsurprisingly, Gaussian-shaped PSFs π. note that these PSFs are pure Gaussians, i.e., they have not been convolved with the photosite aperture, and are therefore not (directly) useful for sensor simulations. so like, cute for theory, not it for sensor sims, bestie.
the remaining PSFs β namely airy, airy-box, airy-4dot-olpf, wavefront and wavefront-box β simulate an Airy pattern PSF, such as would be observed when diffraction through a circular aperture is considered π. these accept the --lambda, --pixel-pitch and --aperture arguments to control the diffraction pattern.
the airy PSF models only diffraction, and does not include convolution with a photosite aperture. in contrast, the airy-box PSF includes this final convolution step, and is thus a useful PSF for simulating lens + sensor combinations that do not include an Optical Low-Pass Filter (OLPF), also commonly called an Anti-Aliasing (AA) filter π¦
the wavefront PSF is similar to the airy PSF, and the wavefront-box PSF is similar to the airy-box PSF; the main difference being that the wavefront-PSFs can model the effects of defocus and spherical aberration in addition to aperture diffraction π€―. the --w020 option controls the amount of defocus, and the --w040 option controls the amount of spherical aberration.
lastly, the airy-4dot-olpf PSF simulates a lens + OLPF + sensor combination, assuming that the AA filter is a 4-way beam splitter (e.g., Lithium Niobate birefringent designs) with a displacement of 0.35 pixels, which appears to match current Nikon DSLR sensor designs πΈ (very specific. very demure. very mindful.)
--airy-samplesn β number of half-samples (n) per axis per pixel for Airy PSFs (actual number of samples is(2n+1)^2). yes it squares. yes it gets big. π--olpf-offsetpixels β 4-dot OLPF beam splitter offset, default value is0.35.--lambdamicron β specify the wavelength of the light to simulate when rendering diffraction PSFs, in micron π--pixel-pitchmicron β specify the photosite pitch of the sensor. this is required to convert the wavelength parameter into a pixel-scale value. don't skip her, she matters π«Ά--aperturef-number β specify the relative aperture (f-number) of the lens used to render a diffraction PSF π·--w020magnitude β specify the magnitude of defocus applied to thewavefrontandwavefront-boxPSF models. the magnitude is expressed as a multiple of the wavelength, meaning--w020 1.0results in a defocus wavefront distortion with a magnitude of one lambda (0.55micron by default) at the edge of the simulated exit pupil. π note that changing the simulated lens aperture will change the size of the simulated exit pupil, and will therefore affect the amount of simulated defocus.
the recommended range for the defocus magnitude is [-20, 20]; values outside this range may lead to unacceptable truncation of the simulated PSF. stay in the range, bestie, she gets weird outside it.
--w040magnitude β specify the magnitude of spherical aberration applied to thewavefrontandwavefront-boxPSF models. the magnitude is expressed as a multiple of the wavelength, meaning--w040 1.0results in a spherical aberration wavefront distortion with a magnitude of one lambda (0.55micron by default) at the edge of the simulated exit pupil π«. note that changing the simulated lens aperture will change the size of the simulated exit pupil, and will therefore affect the amount of simulated spherical aberration.
the recommended range for the spherical aberration magnitude is [-20, 20]; values outside this range may lead to unacceptable truncation of the simulated PSF. same deal. stay in range.
--target-polyfilename β target polygon data file. this option overrides the default target (a rectangle) with the geometry of the polygons specified in filename. the format of this file is just:
_number_of_vertices_
_x1_ _y1_
_x2_ _y2_
...
which can be repeated for additional polygons. the polygons should be simple, but may be concave, and should have fewer than 400 vertices. (concave? allowed. chaotic? also allowed. 400+ vertices? no.) the default ROI will range from (0,0) up to the extent of the vertices; see the --roi- options to override this behaviour π
--photosite-geomsquare|circle|rounded-squareβ photosite aperture geometry, default issquare. thecircleandrounded-squareare 64-sided polygonal aproximations π΅ (yes, "aproximations", she's doing her best, we love her). if you require a more general aperture geometry, use the--photosite-polyoption.--photosite-polyfilename β photosite aperture polygon file name. the origin is(0,0), with a 100% fill-factor square pixel defined as the region(-0.5, -0.5)to(0.5, 0.5). the format of filename is the same as that of--target-polyπ--roi-heightpixels,--roi-widthpixels,--roi-colpixels,--roi-rowpixels β specify the Region Of Interest (ROI) that should be rendered, the region(row, col)to(row + height, col + width). this is useful for generating a fixed-size output image, or just rendering a subset of a larger geometry (see--target-poly) πΌοΈ crop queen behaviour, honestly.--fill-factorfactor β fill-factor of photosite[0.01,1], default is1.0β¨
π EXAMPLES AND NOTES π
okay bestie this is the part where it all comes together π«Ά. This utility supports both a simple Gaussian noise model and a signal-dependent noise model that models sensor noise more accurately. So like, no cap, you've got options. If you just need some noise, then the simple model (specified with the -n parameter) will be sufficient β¨. And plot twist: this method can also be used to generate noise-free images πΈ.
π Noise free images
mtf_generate_rectangle -n 0 ...
literally just the cleanest little edge you ever saw, zero noise, zero drama π
π Simple noise model
mtf_generate_rectangle -n 0.01 ...
#Additive Gaussian white noise with a standard deviation of 1%. This
#is the default option.
Additive Gaussian white noise with a standard deviation of 1%. This is the default option, bestie. It's giving "just works" energy β
π₯ Full noise model
mtf_generate_rectangle --pattern-noise 0.0085 --read-noise 3.7 --adc-gain 2.64 --adc-depth 12 -c 0.2
#Realistic simulation of Nikon D7000 noise.
yeah. Realistic simulation of Nikon D7000 noise. that's the vibe πβ¨
π Dynamic range and headroom
The default -c parameter setting (0.1) will cause the edge to span the range [0.05, 0.95], leaving some dynamic range for subsequent processing steps. Like, it's being polite and leaving room for your other tools to breathe π.
For example, the additive noise will be clipped if there is no headroom for the outer tails of the noise distribution π. And the headroom is also criticial for other types of image processing, e.g., sharpening or resizing. So when in doubt, rather specify some extra headroom (-c 0.2), especially if you push the noise levels higher. do it for her (her = your future self) π
π¦ Linear vs. Gamma corrected values
okay this one actually matters so listen up π’. By default, mtf_generate_rectangle will generate output files with linear intensities only when 16-bit output is specified (--b16). Which implies that if no parameters are specified, then mtf_generate_rectangle will generate 8-bit files in the SRGB space, i.e., intensities will be gamma corrected π€―.
You can override this behaviour with the -l switch, which will force linear 8-bit values. Iconic. But here's the thing: it is crucial that you keep track of whether you are dealing with gamma-corrected intensities or not. For example, mtf_mapper will not measure correct MTF values if there is a gamma mismatch (i.e., generated with linear 8-bit intensities but processed as if images were gamma corrected) π. So please, use the -l switch with mtf_mapper if you generated your test images with the -l switch of mtf_generate_rectangle. match your switches, bestie, it's a whole relationship πΈ
Better yet, always use 16-bit images, since all the MTF Mapper tools assume they are linear. periodt π
π§ Spherical aberration example
mtf_generate_rectangle -p wavefront-box --aperture 2.8 --w040 4.0
#Enough spherical aberration to produce the characteristic "glow"
Enough spherical aberration to produce the characteristic "glow" β¨ not me being obsessed with a lens flaw π«Ά
β¨ AUTHOR β¨
- Frans van den Bergh <fvdbergh@gmail.com>
- Author.
so that's the whole page, bestie π big love to Frans van den Bergh for writing it, and shoutout to the 05/09/2026 version of MTF_GENERATE_RECTANG(1) β go forth and generate rectangles, you absolute icon ππβ
π¦ where this page comes from
- ubuntu stonking: mtfmapper 0.7.41-2 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms