Detector Viewers to different image formats (8-/16-bits) with a user-extension

  • 15 August 2019
  • 9 replies

Userlevel 1

In this thread, I introduce a user-extension DetectorToTIFF to save Detector Viewers as TIFF images. Presently, the user-extension supports Detector Rectangle, which are saved as monochrome 8-, or 16-bits TIFF images. This user-extension is meant to complement the Output Image File field of the Detector Viewer's settings.


Current version: 0.7


This extension has been developed and tested on OpticStudio 19.4 SP2.

The latest release, v0.8, can be found in my latest reply to this thread.


To install the user-extension, download the archive DetectorToTIFF.ZIP and extract it on your computer. This archive contains a local version of this thread and the user-extension DetectorToTIFF.EXE, which you must copy to your \Documents\Zemax\ZOS-API\Extensions folder of OpticStudio.


To use the user-extension, open a non-sequential file, such as User aperture sample.zmx from the \Documents\Zemax\Samples\Non-sequential\Miscellaneous folder of OpticStudio. Then, run a ray trace and open a new detector viewer. Set the viewer as any of the present Detector Rectangle and use Show as with either Grey Sclae, Inverse Grey Scale, False Color, or Inverse False Color, as shown in Fig. 1.

Figure 1. Detector viewer from the User aperture sample file with inverse grey scale display.


Navigate to the Programming tab and open the User-Extension drop-down menu. Select DetectorToTIFF.

Multiple detectors

If you have several Detector Viewers with supported settings open, you may select the one, which you’d like to save by entering the corresponding number in the command window (see Fig. 2).

Figure 2. Detector viewers with supported settings in the User aperture sample file. These correspond to analysis window 2 and 3. Their number in the user-extension are 0 and 1 respectively.

The number to input is based on the number of Detector Viewers with supported settings and their window analysis number. In the User aperture sample file, the two Detector Viewers have supported settings and are attributed the numbers 2 and 3 in their analysis window (see Fig. 2). These Detector Viewers are reported as 0 and 1 in the user-extension, respectively, as shown in Fig. 3.

Figure 3. Command window prompting for a detector number.

Detector viewers are always reported as a list of sequential integers starting at zero in the user-extension.

Bit depth

The next setting to input is the bit depth of the saved TIFF image. Presently, 8- and 16-bits are supported. Type the value zero for 8 bits,and one for 16 bits, as shown in Fig. 4.

Figure 4. Bit depth selection in the command window.

TIFF images stored using a 8-bits format are smaller in size, but are subject to loss of information during the digitization process. While two images might appear to be the same when saved to 8- and 16- bits, as shown in Fig. 5A and B, respectively. When performing post-processing steps, such as changing the scale to display the logarithm value of the pixels, the loss of information might have a significant effect, as shown in Fig. 5C and D.

Figure 5. Effect of the bit depth of displaying images with a logarithmic scale. A. 8-bits TIFF image. B. 16-bits TIFF image. C. Corresponding 8-bits TIFF image with a logarithmic scale. D. Corresponding 16-bits TIFF image with a logarithmic scale.


The choice of an appropriate bit depth is left to the user.


The resulting TIFF image (see Fig. 6) is saved in the same folder as the ZMX file with the same name, only the extension is changed to TIFF.

Figure 6. Resulting 16-bits TIFF image from the User aperture sample file.

At the end of the user-extension, the user is asked to type ENTER to confirm the closure of the command window and the user-extension.


The DetectorToTIFF user-extension is provided here as it is. It might still contains bugs, and Zemax Technical Support is not covering this user-extension. If you observe any bugs, please report it in this discussion.

I am also planning to extend the capabilities of this user extension, here are some of my ideas:

  • To support other detectors, such as the Detector Color

  • To incorporate other image file formats

Let me know if you think these ideas should be implemented or if you think they are irrelevant. Feel free to also reply with your own ideas as to what should be implemented in this user-extension to make it more functional.

9 replies

Is there a way to have the same with PNG (esp. 16 bits PNGs) ?
Userlevel 1
Hi Ray,

I have updated the User-Extension to support the PNG file format in 8- or 16-bits. It is now called DetectorToImage.

I also updated the README document that comes with the archive, but not this forum post. Here's the version number:


Current version: 0.8



This extension has been developed and tested on OpticStudio 19.4 SP2.

Userlevel 4
Badge +3

For those who attended or watched on-demand my ENVISION presentation about Zemax's customer success team and the tools/resources available to you, our customers, this is one of the OpticStudio extensions that I mentioned. 

This extension allows you to save the output of an analysis without the analysis window frame, so that it can then be input into your system as a source.

Search keywords: without frame, frameless, tiff, jpeg, jpg

Badge +2

Is there a way to invoke this from a macro?  Right now I loop over a parameter of interest in ZPL, then use SAVEDETECTOR to write data to a file and then use a special parser to import DDR data into python.  Writing directly to a TIFF file would be simpler and wouldn't require parsing of a DDR.  You'd get extra header for being able to pass in an array of strings that get written as the TIFF header!

Userlevel 6
Badge +2

Hi Steve!

No this can't be called from a macro. 

- So I guess that the code would need to be replicated within a macro.

- Or you could move all your code to Python. In Matlab for example, there is a function called imwrite to write an array into an image. 


Badge +2

Hi David,

Would you please post the source code?  I think you can actually write raw DDR (double) data.  I did this with GIA data in python, and expect it would work with DDR data as well.

from PIL import Image



TIFF actually seems to support at least 5 formats:

{16-bit, 12-bit, 8-bit,16-bit floating-point, 64-bit double-precision floating-point}

If you aren't able to share the source code, would you please add 64-bit double-precision floating-point TIFF support?




Hello David,

Current linear type intensity display output and the BMP, JPG, PNG files of Image Simulation (IS) do not provide the required low intensity diffraction patterns. We need logarithmic type display to effectively use IS feature of ZOS when working with small beam profiles delivered by diffraction-limited optical systems.

Could you extend your technique to provide Image Simulation (IS) display/output file in logarithmic scale, as an option?



Diffraction image of a spot beam displayed in linear scale while preferred in logarithmic scale


is here plans for making it standard feature for NSC detector? 

12-bit sensor common today

@David Nguyen Could you share way to create similar extention?