How to create binary IMA and BIM files

There are a number of analysis features in OpticStudio which use IMA and/or BIM files to provide a description of an extended source in sequential mode. This article explains how to create binary IMA and BIM files, which are occasionally needed for use with the Image Analysis features in the Sequential Mode of OpticStudio.

Authored By Sanjay Gangadhara


Article Attachments


OpticStudio provides IMA and BIM files in a variety of illumination patters in order to provide a description of an extended source in Sequential mode. However, there may be cases where a user-defined illumination source is needed, requiring the user to create their own IMA or BIM file.

Simple ASCII IMA files may be generated in a text editor and illumination sources that can be represented with a .BMP or .JPG file may be created via use of the Geometric Bitmap Image Analysis feature. However, there may be a cases where the illumination source is too complex for an ASCII file and cannot be described by a .BMP or .JPG. For these special circumstances, binary IMA or BIM files are required. This article describes how such files may be generated using simple C code.

Writing the code which generate the files

An example of a C code (Image files.c) used to generate a checkerboard illumination pattern is provided as an article attachment. This code generates three types of files which are used by OpticStudio: an ASCII IMA file, a Binary IMA file, and a Binary BIM file. More information about these file types may be found in the Help System under The Analyze Tab (sequential ui mode)>Image Quality Group>Extended Scene Analysis>Geometric Image Analysis. In this case, the illumination pattern generated in each file is a 5x5 checkerboard, where the intensity values alternate between 0 and 1 (or 255 for the case of the binary IMA file, which is the equivalent maximum value). ASCII IMA files may also be generated and edited with a text editor, of course. This code generates all types of IMA and BIM files that are supported by OpticStudio for completeness.

The code itself is straightforward. The initial part of the program is dedicated to specifying names for the three files, and then opening those files so that they may be written to. Make sure that the directory is set to the correct location of your IMA file folder. For most, the Zemax folder is located in the Documents.


After declaring variables that will be used later in the code and defining the size of the illumination array in x and y, the necessary header information necessary is written to each file:

more code

Finally, illumination data are written to each file. The data alternate between minimum and maximum values, to produce a checkerboard pattern:

more code

Compiling the code

This code can be compiled using Microsoft Visual Studio 2017 (or your favorite C compiler). The procedure for this compilation is very similar to that described in the Knowledgebase article “How to compile a User-Defined DLL”. In this case, rather than specifying the project as a Win32 Project or a Win32 Dynamic-Link Library, you should specify it as a Win32 Console Application. We can do this by opening an empty Windows Desktop Wizard C++ project.

specifying as win32

This application will be created as an Empty project:

application settings

We want to release the project as a Win32 type.

When the code is compiled, it will generate an application file with the name provided by the user during setup. The IMA and BIM files are generated by running this application (i.e. by double-clicking on the application icon). As indicated in the code, the files will be written to the {Zemax}\IMAFiles directory.

Viewing the results

A simple OpticStudio design (IMA files.zar) which illustrates the use of each of these files (Checkers_ASC.IMA, Checkers_BIN.IMA, and Checkers_BIN.BIM) within the Geometric Image Analysis feature is also provided as an attachment to this article. The checkerboard pattern is clearly visible for each case:

checkerboard pattern

Python converter

A Python converter is available on the Code Exchange (login to view this space): 



Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.