Skip to main content
Solved

Image Simulation in Matlab - Black Output Image


BeauDiddley

Hi all,

 

I am looking to build an API in MATLAB to perform image simulations in Zemax. I am having trouble with the basic case.

My MATLAB Standalone Application:

function [] = BeginApplication(TheApplication, filename)

import ZOSAPI.*;

TheSystem = TheApplication.PrimarySystem;

TheSystem.LoadFile(filename, false);

% Create analysis

im_analysis = TheSystem.Analyses.New_ImageSimulation();

im_settings = im_analysis.GetSettings();

im_settings.OutputFile = 'testfinal.BMP';

im_analysis.ApplyAndWaitForCompletion();

end

 

If I run this on the “Double Gauss 5 degree field.zmx” sample file, I get an image generated that simply [0,0,0]  pixels.

I can run the simulation on the same .zmx file in OpticsStudio without issue.

 

Any ideas what I am doing wrong?

 

 

Best answer by BeauDiddley

That worked great, Csilla! Thank you.

 

Csilla Timar-Fulep wrote:

Hi @BeauDiddley ,

Thanks for your question here on the Community Forums!

I have tested your MATLAB code on my side, and when the Zemax sample file was loaded correctly from the API, then I got a reasonable output as below:

I only got an empty output like you when the sample file was not loaded correctly from the API:

Please note that you need to define the full path together with the extension of the file, and not just the file name, in order for the LoadFile function to work correctly. 

You may use the following code to load the Double Gauss file:
samplesFolder = TheApplication.SamplesDir;
DGfile = System.String.Concat(samplesFolder, '\Sequential\Objectives\Double Gauss 5 degree field.zos');
TheSystem.LoadFile(DGfile, false)
Also, the LoadFile function returns a bool variable which indicates whether the loading process was successful or not. Please double-check that to make sure the file loading was completed successfully.

Best,
Csilla

 

View original
Did this topic help you find an answer to your question?

3 replies

Benjamin.N
Forum|alt.badge.img
  • Visible
  • 34 replies
  • June 29, 2023

I recreated your example in Python and it outputs a more meaningful file:

    System = ZOSAPI.ZOSAPI_Connection().CreateNewApplication().PrimarySystem
    System.LoadFile(file, False)

    im_analysis = System.Analyses.New_ImageSimulation()
    interface = ZOSAPI.Analysis.Settings.ExtendedScene.IAS_ImageSimulation
    im_settings = interface(im_analysis.GetSettings())
    im_settings.OutputFile = 'testfinal.BMP'
    im_analysis.ApplyAndWaitForCompletion()

Note that the “interface = ...“ part is an adaption to Python which should not be necessary for Matlab (to my knowledge).

 


Csilla Timar-Fulep
Zemax Staff
Forum|alt.badge.img+2

Hi @BeauDiddley ,

Thanks for your question here on the Community Forums!

I have tested your MATLAB code on my side, and when the Zemax sample file was loaded correctly from the API, then I got a reasonable output as below:

I only got an empty output like you when the sample file was not loaded correctly from the API:

Please note that you need to define the full path together with the extension of the file, and not just the file name, in order for the LoadFile function to work correctly. 

You may use the following code to load the Double Gauss file:
samplesFolder = TheApplication.SamplesDir;
DGfile = System.String.Concat(samplesFolder, '\Sequential\Objectives\Double Gauss 5 degree field.zos');
TheSystem.LoadFile(DGfile, false)
Also, the LoadFile function returns a bool variable which indicates whether the loading process was successful or not. Please double-check that to make sure the file loading was completed successfully.

Best,
Csilla


BeauDiddley
  • Author
  • Monochrome
  • 3 replies
  • Answer
  • July 13, 2023

That worked great, Csilla! Thank you.

 

Csilla Timar-Fulep wrote:

Hi @BeauDiddley ,

Thanks for your question here on the Community Forums!

I have tested your MATLAB code on my side, and when the Zemax sample file was loaded correctly from the API, then I got a reasonable output as below:

I only got an empty output like you when the sample file was not loaded correctly from the API:

Please note that you need to define the full path together with the extension of the file, and not just the file name, in order for the LoadFile function to work correctly. 

You may use the following code to load the Double Gauss file:
samplesFolder = TheApplication.SamplesDir;
DGfile = System.String.Concat(samplesFolder, '\Sequential\Objectives\Double Gauss 5 degree field.zos');
TheSystem.LoadFile(DGfile, false)
Also, the LoadFile function returns a bool variable which indicates whether the loading process was successful or not. Please double-check that to make sure the file loading was completed successfully.

Best,
Csilla

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings