ActionPhotos by Marianne
Home -> Tech Info -> Optical Simulation
Update, Vcam Ver. 1.50: Adds switches /Z, /N, /G, /E and /J to provide more options for the raw-file image patch output. See descriptions below. As a convenience, frequently-used switches may be placed into file Vcam_sw.txt, which is scanned before the command-line switches are parsed; the command line switches have priority. Switch /Q is added, to alter the spectral distribution of light assumed for generating the diffraction contour. It is no longer necessary to use the /L switch to enable the analysis parameter output, or the image patch output to Output.NEF.
For reasons of size, the template raw file has been placed into a separate archive. The earlier simulation application, Conv2, is no longer supported since Vcam includes all of its features.
New Product Introduction, Vcam Ver. 1.00: A Virtual Camera, based on Conv2 ver. 1.24, this application adds image output to file Output.NEF, when a .NEF file of that name is present and the test object is a periodic signal that spans the full workspace. Supports all Conv2 features and switches; new switches /X and /Y are added. NEF format must be 14-bit uncompressed; a template version is included in the archive. By default, the output image patch is approximately 400x100 pixels for pre-AA or post-AA output only, or 400x200 pixels when both output options are enabled. The image patch consists of the sensel values normally output by the /L switch, shifted across all offsets to create vertical lines with a slight slant (40:1). The purpose of the image patch is to allow the user to evaluate end-to-end performance of the entire photographic process from test subject to converter output, assess raw-converter performance, and test the effects of converter settings on the quality of the converter's image rendering.
Overview and Features
The Optical Simulation tool presented here is designed to answer questions related to resolution, diffraction, AA filter effects, lens quality, and how our cameras "see" the smallest details. For example: What does diffraction look like? How does the AA (anti-aliasing) filter affect an image? Should I select a camera with or without an AA filter? Can diffraction substitute for the function of an AA filter? How does lens quality, focus precision and lens aperture affect the resolution my camera can achieve? When will moire' (aliasing) show up? How do optical imperfections combine to limit resolution? How do different test-objects compare for evaluating lenses and cameras? When is my lens diffraction-limited? How strong is my camera's AA filter?
The simulation tool, Vcam.exe, starts with one of several basic object patterns, then applies defocus, diffraction, lens point-spread and/or AA filtering as specified by the user. The resulting image is presented in a .bmp file for viewing (both pre-AA-filter and post-AA-filter versions), and numerical output is available to show how the camera's sensor responds to the image, or as a "dump" of the image centerline values. The sensor-response output reveals camera resolution and sensitivity to moire', while the image dump allows detailed study of the image presented to the sensor.
Calculations are carried out by dividing the image space into samples which correspond to 1/20th of the width of a single sensor element (sensel). Thus the area occupied by one sensel is represented by 400 computing samples. The digital workspace is 1001 samples wide by 301 samples high, or 50x15 sensels. Spatial parameters such as AA-filter shift and object feature size are adjustable in units of 1/20th of a sensel width. Other parameters such as lens PSF diameter and COC diameter may be specified as any value, but will be quantized to 1/20th-sensel units for computing purposes. The coordinate system origin is placed at the center of the workspace, and test objects (unless offset) are centered at this origin.
By default, diffraction contours are computed for the distribution of wavelengths detected by a typical camera green channel (specifically, weighting is taken from the Nikon D3 green-channel response curve with Halogen illuminant). This allows the simulation to accurately model RAW data from the camera sensor's green channel, which is normally selected for various types of image analysis. Other spectral distributions may be specified; see the /Q switch description below.
Image output is written to the file Output.bmp. If AA-filter shift is non-zero, this will include two 1001x301 image panes, with the upper image representing the post-AA-filter result and the lower image showing the pre-AA-filter result. Subsequent runs of Vcam.exe will overwrite Output.bmp, so this file should be re-named if the user desires to preserve it. Since the 8-bit output image is limited to representing values up to 255 only, the image values are auto-rescaled to this range, in cases where highlight clipping would otherwise occur. To improve visibility of faint areas, upscaling up to 2 stops is provided for low-amplitude images.
Numerical data output, and the setup parameters, are appended to file Trace.csv, which then acts to accumulate information from consecutive runs. Numerical data is never re-scaled.
Numerical Analysis:  In cases where a periodic test object is specified and that object spans the full width of the output image, a raw-data image patch is written to file Output.NEF, if it exists, and additional parameters are computed:
H(f): This is the signal transfer function, and specifies what fraction of the input signal appears at the output; the range is 0 to 1 nominally, but can be higher if sharpening is used. There are three frequency ranges in which this parameter is evaluated differently: 1) For signals below Nyquist frequency, H(f) represents the average MTF over an infinite span; 2) For signals exactly at Nyquist frequency, i.e. when T=2, H(f) will vary with offset (phase shift between signal and sensel position), and at the default zero-offset its value will be doubled (use the -O switch to investigate dependency on offset); 3) For signals above Nyquist frequency, H(f) is zero since these signals cannot be represented.
Note: H(f) and the other parameters are evaluated across an interval which corresponds exactly to an integer number of beat cycles between the signal frequency and sampling frequency (1/sensel pitch). This provides accurate values which are representative of the averages which would be measured for signals of infinite span. However, with long signal periods, there are some values of T where the beat cycle would not fit within the extended workspace. In these cases, T will be adjusted downward slightly so that the resulting beat period may be accommodated.
Xchroma: This represents the degree of cross-chroma, also known as color moire', caused by aliasing. This artifact of aliasing is one of the most noticeable in images, producing false yellow and cyan edges with Bayer RGB sensors. Range is 0 to 1, with 0 representing no cross-chroma, and 1 indicating the heaviest level. The sophisticated demosaicking algorithms used by modern raw converters will attenuate most of the cross-chroma in areas where textures are fairly uniform, but may have difficulty where very fine textures change abruptly.
Alias: This is the effective amplitude of signals present at frequencies below the signal frequency, which are a product of aliasing. When the input frequency is above Nyquist, i.e. when the switch -T parameter is less than 2, Alias substitutes for H(f) to give the magnitude of the output.
Moire: The envelope of the output data is analyzed to find the level of amplitude modulation, known as moire, caused by superposition of aliased signals. A value of 0 indicates no moire, while a value of 1 indicates moire of maximum modulation. In images, moire below 0.1 would appear as slight, 0.2 to 0.3 is very noticeable, and 0.5 or higher is heavy. Visibility of moire is also affected by the beat frequency, and is most noticeable at low beat frequencies where the moire cycles are wide.
The application Vcam.exe is a console application, which is run from a Windows Command Prompt window, and is controlled by command-line switches. A switch is a single letter prefixed by a hyphen '-' or forward slash '/' or alternatively, switches with a parameter value may omit the prefix and use an equals sign '=' suffix before the parameter value. Spaces separate switches, so embedded spaces are not permitted except where required (/J, /K and /Q switches, which have two parameters). Recognized switches are:
Displays program-usage information.
Outputs DN values for the horizontal line of sensels through the image center. This represents the RAW image data that would be gathered by a sensor at the image plane. Sensel positions are numbered from -27 (left end) to 27 (right end). Format is comma-separated, so the listing may be pasted into a spreadsheet for plotting or further analysis. To minimize boundary effects, the sensel line stops a little short of the image ends.
The -K switch enters values for sharpening filters, and is only used in combination with the -L switch, to operate on the computed sensel-DN outputs. Note that sharpening does not affect the image written to file Output.bmp. This is the only switch which requires an embedded space, to separate the two values entered. Range for xx and yy is 0 (no sharpening) to 2 (maximum sharpening). Typically, values in the range 0 to 0.5, corresponding roughly to 0% to 50% sharpening in most raw converters, will be used. The higher values may be useful in cases where image blurring is heavy. The first parameter (xx) specifies sharpening to be applied to the "Pre-AA" output values, and the second parameter (yy) specifies sharpening to be applied to the "Post-AA" output values.
Sharpening affects the values of the Peak-to-peak, H(f), Xchroma, Alias and Moire parameters. For example, it is entirely possible for H(f) to exceed unity when sharpening is applied. When deciding on the value of sharpening to use, it is best to evaluate the effect by observing how the P-P parameter varies. A step object is very useful for quantifying sharpening effect, e.g., "Vcam T=16 W=8 O=4 K=xx yy /L" will show the degree of sharpening halo (overshoot/undershoot) that results.
Similar to the L switch, but in this case, a single sensel is micro-stepped across the image center, with step size of 0.1x the sensel width. This produces a series of RAW data values equivalent to those taken along slanted edges in test charts, for example, but without requiring a slanted-edge to be set up. The sampling sensel is scanned from 2 sensel-widths to the left of image center, through 2 sensel-widths to the right of center. For each sensel position, data from a 19x19 array of computed image values is averaged, rather than full 20x20, to simulate light loss at the borders of microlenses; this binning approach applies to the -L switch also.
This produces a detailed image "dump" of values along the center horizontal line of the output image, starting 2 sensel-widths to the left of the origin, and continuing to the right through the last non-zero sample. This data is intended for precision measurement of image contours, determination of half-power or quarter-power points, etc.
Note that the /L, /M and /D switches are mutually exclusive, and only the last one entered on the command line will be in effect.
This changes the format of data written to file Trace.csv, so that all output appears on a single line. Intended to allow data accumulated from successive runs to build up as a table in a spreadsheet.
Sets lens aperture, or f-stop, where xx is a real number in the range 1.0 to 45. May also be entered as F/xx, -Fxx or /Fxx. This determines the diffraction contour diameter. Default value is f/4. Note that larger values may increase computing time greatly.
Set the corner position for image patch written to Output.NEF. Default is (X,Y) = (0,0), but a small bias is added to compensate for border loss when the file is rendered by a converter. Entered values are limited where necessary, to keep the image patch from exceeding the right-side and bottom boundaries.
Specifies a slant from vertical, when the vertical-bars test object is selected. Z may range from -1.0 to 1.0, corresponding to full left slant (45 degrees counter-clockwise from vertical), to full right slant (45 degrees clockwise from vertical). Intended for testing of slant-edge quality in raw converter output. Note that slanting the vertical-bar pattern is also reflected in the Output.bmp file, and in the analysis parameters described above.
Changes the raw-file image patch from overwrite mode, to modulation of the existing image. Intended to preserve noise in the original file, if the detail effects of noise-reduction are to be studied. The optional parameter xx sets the modulation depth, and may be 0.0 to 1.0. Creative uses of the /N switch include overlapping image patches to generate more complex patterns, and modulating images containing various colors and subjects.
Sets the gain (exposure) for the raw-file image patch. Range is 0.1 to 10.0. Effective either with, or without, the /N switch.
Sets the Extent of the raw-file image patch. Parameter nn specifies the width of the patch in pixels, and may range from 100 to 1000. Patch height is scaled mildly (less than direct-proportion) with patch width.
May be used to redefine the white and black levels and hue, when overwrite mode is used for the raw-output image patch (i.e., when the /N switch is not used). Parameter nn is the DN value for a single color channel, and may range from 0 to 12,000. Parameter m selects the color channel as follows: m=0 for Red channel in white level, m=1 for Green1 channel in white level, m=2 for Green2 channel in white level, m=3 for Blue channel in white level, m=4 for Red channel in black level, m=5 for Green1 channel in black level, m=6 for Green2 channel in black level, and m=7 for Blue channel in black level.
Note that the /J switch affects the raw-file image patch only. It does not alter Output.bmp, and has no effect on the analysis parameters.
Sets the spectral amplitude at wavelength nn nanometers. Wavelength may be 400nm to 700nm. Amplitude scale is arbitrary, since the diffraction contour will be normalized after processing. In many cases, building a full spectral specification will require a large number of /Q switches to be used; these may be placed into the Vcam_sw.txt file since they cannot be accommodated on the command line. The default spectral distribution corresponds to the response of the Nikon D3 green channel, with halogen illumination; although this is concentrated at mid visible wavelengths, it does include the full range of 400nm-700nm. A reference file with this distribution is provided in the application archive, which can be edited to make adjustments to the spectrum.
As a special case, using nn=0 will apply amplitude xx to the full wavelength range. This is convenient if one wishes to use a flat spectral response, or zero out all wavelengths, followed by setting just a single, or a few, wavelengths. Note that if all wavelengths are set to amplitude 0, the diffraction convolution step will be bypassed.
Sets the f/1.4 "circle of confusion" or "blur circle" diameter, in microns, when defocusing is to be simulated. The value will be scaled down automatically by the simulation, if apertures narrower than f/1.4 are chosen. May also be entered as -Cxx or /Cxx. C may be positive if the lens is front-focused or negative if the lens is back-focused. The sign of C will determine how defocus combines with SA, but if U is set to 0, the sign of C will not matter. Default value is 0.0 microns. If both U and C are 0, the defocus-convolution step will be skipped.
Sets the diameter, in microns, of the spherical aberration (SA) circle produced by the lens at f/1.4. The value will be scaled down automatically by the simulation, if apertures narrower than f/1.4 are chosen. May also be entered as -Uxx or /Uxx. U is positive if the lens SA is undercorrected, or negative if the lens SA is over-corrected. The effect of spherical aberration is combined with defocus (switch /C) by a projection algorithm, separate from the convolution steps. Default value of U is 0.0 microns. If both U and C are 0, the defocus-convolution step will be skipped.
Set the lens point-spread half-power diameter, in microns. A Gaussian profile is assumed for the point spread function, since it is intended to account for random manufacturing imperfections and design non-idealities. May also be entered as -Pxx or /Pxx. Default value is 0.0 microns, which bypasses this convolution step.
Set the AA-filter shift, in units of sensel-widths. May also be entered as -Axx or /Axx. Default value is 0.4, which specifies that the AA filter shifts the image +0.4 sensel-widths and -0.4 sensel-widths in each axis. Setting a value of 0 will bypass the AA-filter convolution step and suppress image and numerical outputs for that step. Using a negative number will disable image and numerical outputs for the pre-AA convolution step, if those are not of interest.
Set the assumed sensel width, in microns. May also be entered as -Sxx or /Sxx. Default value is 4.8. Allowed range is 1.5 to 25 microns.
Select a horizontal row of 2*nn+1 impulses as the object. Default object is a single impulse at image center, which is the same as R=0. May also be entered as -Rnn or /Rnn. Default impulse spacing is 2 sensel widths (unless changed with the T switch) which places the impulses at the Nyquist sampling frequency. If used without the 'nn' value, the R switch will produce a row which spans the entire workspace.
Select a series of 2*nn+1 equally-spaced vertical bars, at 50% duty cycle, as the object. This is a common test-chart feature, and is useful for evaluating overall system MTF and camera susceptibility to moire'. May also be entered as -Bnn or /Bnn. If used without the 'nn' value, the B switch will produce a set of bars which spans the entire workspace.
Sets the period of repeating objects (impulses or vertical bars), as a multiple of sensel widths. May also be entered as -Txx or /Txx. For example, T=3 sets the repetition interval to be 3x the sensel width. Minimum value is 0.1 and maximum is 30. This switch may also be used after the R switch, to change the impulse spacing to T.
If used without the W switch, the width of vertical white bars will be set to T/2. If used without either the R or B switches, vertical bars will be selected for the object type.
Sets the width of the white vertical bars, as a multiple of sensel widths. May also be entered as -Wxx or /Wxx. For example, W=1.5 sets each white bar to be 1.5x the sensel width. Minimum value is 0.05 and maximum is 30. Has no effect for objects other than vertical bars.
If used without the T switch, the object period will be set to W*2. If used without either the R or B switches, vertical bars will be selected for the object type. If preceded by the R switch, the W switch has no effect.
Sets an offset value which will shift the object to the right xx sensel widths. May also be entered as -Oxx or /Oxx. With the default offset of 0, objects are centered in the image, i.e., the object will be symmetric about the origin. Use of an offset allows the object to be asymmetrical. Maximum allowed value is equal to W in most cases, but if a repeating object is used which spans the full workspace width, offset is limited to 1 sensel width. Please note that in the latter instance, offset has no effect on the analysis results unless signal frequency is exactly at Nyquist.
The /a0 switch turns the AA-filter simulation off, so the output will only show the pre-AA image. The r=3 switch creates a row of 7 (2*3+1=7) impulses (star-like objects), and we see the blurring that is caused by diffraction at the default aperture of f/4:
This generates default output, but with a little more diffraction softening due to the f/5.6 aperture. The output includes both pre-AA-filter (bottom) and post-AA (top) versions. Note that the action of the AA filter on very small images like this, creates four distinct "copies:"
The object is 7 vertical bars at default settings, which is bar-width equal to sensor-width, in other words, the white bars occur at the Nyquist frequency. We see that the AA filter smooths these bars out to nearly mid-gray. If the AA-shift had been set to 0.5 instead of the default 0.4, the result would be completely mid-gray. As an exercise, try running this with the -L switch, and then look at the listings in the Trace.csv file to see how the sensor responds to the two versions of the image:
Here we have 3 vertical bars, which are much narrower than the sensel. This is a very high spatial frequency of 2.5x Nyquist. Coincidentally, the bars are spaced out at the same interval that the AA filter produces, so this prevents the AA filter from "filling in" the spaces between them, as it would do with most fine bars like this:
Spherical aberration (SA) interacts with focus offsets to produce a range of different profiles of the circle of confusion, or "blur circle." In this family of examples, a lens with undercorrected spherical aberration is shown at 3 different aperture settings, and a range of focus settings from front-focused (producing background-type bokeh) to back-focused (producing foreground-type bokeh). The focus range was produced by letting parameter c vary from +12 (left column) to -36 (right column) in steps of 4.
For reference, the blur circles produced at f/1.4 without any SA are shown between the f/1.4 and f/2 rows; these demonstrate that the "true" focus point, where focus occurs for very narrow apertures, is at the fourth column from the left (parameter c is 0 for this column). In contrast, with SA present, the lens must be focused quite differently to achieve sharpest focus at f/1.4; this "focus shift" is indicated in red.
The profile of the blur circles determines the quality of bokeh. Lenses with undercorrected SA such as this one, produce smooth background bokeh due to the very gradual fade-out of the blur circle toward its perimeter. In contrast, foreground bokeh becomes harsh because so much light is concentrated at the perimeter of the blur circles. You can see that this harshness, and the focus shift accompanying SA, is reduced at narrower apertures.
Last Update: Jan. 29, 2013.