Python Converting an image into a Binary BIM Image file

  • 17 January 2022
  • 6 replies
  • 573 views

Userlevel 6
Badge +2

The download contains a Python script a script to write an image (JPG) into a Binary BIM Image file. The PNG, GIF, TIFF, and BMP should also be supported but haven't been tested.

 

Click here to download

Date Version OpticStudio Version Comment
2022/01/01 1.0 - Creation

 


6 replies

Thanks  Sandrine!  I was just going to try to write my own code to do this, so you’ve saved me some time.

I’m trying to do a coherent image analysis for the optical system I have defined in Zemax.  The input image is actually a higher order “barbell” Hermite Gaussian mode, the 10 or 01 mode.  I’m using LightPipes to generate a numpy array that I want to export into the .bim format.  But I am not sure about one detail.  Is the .bim image I use as the input to generate a coherent image using the “partially coherent image analysis” tool supposed to be an intensity image?  If so, is there any way to calculate the coherent image in Zemax of a complex input image?  The HG barbell modes have different signs so an intensity input image won’t work to capture the true coherent image of them. 

 

Thanks!

Userlevel 6
Badge +2

Hi Stephanie

If you use a BIM image, the data values are interpreted as relative irradiance values (so flux/area) not amplitude. But you could use a ZBF file as the input. A ZBF file represents an array of electric fields. There is some information about this on the help file (and also a script above). Let us know if that helps.

Thanks Sandrine!  That helped a bunch.  I was confused because those files ask for Gaussian beam parameters and the Gaussian beams feature I believe only works for the 00 mode, but it looks like the gaussian beam information is basically ignored, at least the Rayleigh length in the coherent image calculation.  I wasn’t sure how to define Rayleigh length for the higher order mode so I tried two values very far apart and it didn’t affect the coherent image, as I figured should be the case from the math.

I’m using 01 and 10 modes that are polarized in the direction that they have only one mode, if that makes sense.   For example the 01 mode with two lobes along y is polarized in the x direction.  I managed to write the ZBF files for both of these modes and they look correct in the beam viewer in Zemax, when I check the Ex and Ey irradiance there to make sure the polarization is correct.  But only the 01 mode propagates correctly.  The 10 mode, even though it looks correct in the beam viewer, only gives me a result of 0 after the coherent image propagation no matter what I tried, and that’s definitely not correct.

BTW, the 10 mode is the input mode where I needed to use ispol=1 and make Ex=0 for all pixels.  The other one I didn’t think I needed to do that because it’s polarized in x and the input I’m giving is Ex for that mode the beam looks correct in the beam viewer.  But the 10 beam propagates to 0, even though the beam looks correct in the viewer.  Do you have any idea what I could be doing wrong?  I tried selecting and unselecting various option to see if it would help but I kept getting 0 for the entire beam.  Where did all my power go?

 

Thank you for your time!

Stephanie

Userlevel 6
Badge +2

Hi Stephanie

From your description, everything looks correct so I am a bit puzzled.

Would you be able to open a case on support and share your files? I can have a closer look.

Hi Sandrine

My sincere thanks for posting this code that has a great value in my work too.

However, I am struggling with one issue. It is adding a white band at the bottom of the generated BIM file that is causing some issues with calculating the centroid of a spot image by IMAE operand. I tried with various JPG files and all of them have that white band at the bottom of the BIM file. As an example, I am attaching the jpg of spoke wheel, that is also a sample file of IMA folder of Zemax along with its BIM file (generated by your code) and the corresponding GIA image diagram by Zemax. I am not a Python expert to figure out the problem and so may I request you to please check and rectify the code for me? Greatly appreciate your help! Thanks!

Jpg to BIM conversion leaving a white band at the bottom 

Krishna

Hi Sandrine,

I made a small change to the code as shown below. That resolved the issue. Please confirm this is OK. 

I cropped the JPEG square before, converting to binary image. Works well now on my other files too. Thanks!

Krishna

Reply