rafael-fuente / diffractsim

✨🔬 A flexible diffraction simulator for exploring and visualizing physical optics.
https://rafael-fuente.github.io/simulating-diffraction-patterns-with-the-angular-spectrum-method-and-python.html
Other
754 stars 93 forks source link

Possibility of Phase-Object Diffraction Simulation #6

Closed FishWoWater closed 2 years ago

FishWoWater commented 2 years ago

Hi! Thanks for your really amazing work! I am a newbie in optics and I am wondering whether it's possible to produce diffraction like image And here is the light field with the description from the paper

A laser beam emitted from a He–Ne laser at a wavelength of 632.8 nm (NEC Electronics Inc. GLG5002) was first spatially filtered by a pinhole with an aperture of 10 µm and then collimated by a lens with a focal length of f= 200mm. The plane wave was guided to illuminate a phase object, producing intensity images as shown in Fig. 5b. To acquire the diffraction pattern, we placed the camera (SensiCam EM, pixel pitch: 8 µm) at a distance d= 22.3mm from the phase object.

image

Appreciate it a lot if you could help me about this:) Wish you a good day!

rafael-fuente commented 2 years ago

Yes, it's perfectly possible. In fact, I'm currently working on an interface for the repository for adding phase masks and even generating and reconstructing phase holograms. It will be ready in a few days (next week).

How is your phase object specified? As a gray map image? Wish you a good day too!

FishWoWater commented 2 years ago

Thanks for your reply! @rafael-fuente Yes, the phase object is specified as as gray map image(like the ground-truth column in the figure above) and is expected to produce diffraction like the DIffraction column in the figure. Can't wait to try the new features :)

FishWoWater commented 2 years ago

@rafael-fuente Could you please give some insight on how to implement phase transformation by phase masks? I have read about your post and Section5.1 in Goodman's book, which talks about phase transformation caused by thin lens. I guess transformation caused by phase object may be somewhat similar, but I failed to find any material about that. Could you please give some insight on how to convert a gray map image(phase mask) into phase transformation function \Phi(x, y, 0) so that I can try to implement by myself : ) image

Appreciate your help!

rafael-fuente commented 2 years ago

It's done. I added the new features I said. Specify your phase mask using phase_mask_path argument in add_aperture_from_image method

For your example:


import diffractsim
diffractsim.set_backend("CPU") #Change the string to "CUDA" to use GPU acceleration

from diffractsim import MonochromaticField, mm, nm, cm, PhaseRetrieval

#Add a plane wave
F = MonochromaticField(
    wavelength=632.8 * nm, extent_x=30 * mm, extent_y=30 * mm, Nx=1800, Ny=1800, intensity = 0.005
)

# load the hologram as a phase mask aperture
F.add_aperture_from_image(
     amplitude_mask_path= "./examples/apertures/white_background.png", 
     phase_mask_path= "./examples/apertures/cat.png", image_size=(10.0 * mm, 10.0 * mm), phase_mask_format = 'graymap'
)

# plot colors at z = 0
rgb = F.get_colors()
F.plot_colors(rgb)

# propagate field 80 cm
F.propagate(80*cm)
rgb = F.get_colors()
F.plot_colors(rgb)

And this is the final diffracted pattern: cat

Note: For reconstructing exactly your diffraction pattern I need to know the phase object size

For the phase hologram generation, take a look at this example

It generates the following phase mask, which is encoded by default using a cyclic HSV colormap instead of grayscale. (red color represents 2*pi or 0*pi phase shift). The reason I use HSV colormap is that is cyclic. If you interpolate the grayscale image at the edges between 2*pi (black pixel) or 0*pi (white pixel) it will produce a wrong value.

snowflake_phase_hologram

When diffracting the phase mask to the Fourier plane, it reconstructs a snowflake image:

snowflake

FishWoWater commented 2 years ago

Excellent! You did a really great job!! I think it's a perfect starting point for me, I am going to try right now :+1:

FishWoWater commented 2 years ago

Hi! I was able to produce diffraction pattern like image but is there any way to retrieve phase mask as the grayscale image like image

It seems that implemented GS algorithm assumes we know target amplitude (in the fourier plane, Fraunhofer diffraction model). But what happens in my case is Fresnel diffraction, should I exchange the roles of source_amplitude and target_amplitude in GS algorithm? I tried and saved retrieved mask as follows: image I can see the rough contour of the face, but how can I achieve colorful/structured/good-looking like the phase mask input? Or is there any magic / something I get wrong in the pipeline?

Thank you very much @rafael-fuente

FishWoWater commented 2 years ago

I managed to solve this problem by integrating concrete light propagation into GS algorithm, thanks: )

rafael-fuente commented 2 years ago

The phase holograms are perfectly fine, as they are reconstructed in the Fourier plane. What you may want to generate are Fresnel holograms, which look more like the image you attached. I would definitely add the possibility to generate Fresnel holograms in a near future! 🙂

Sorry for my late reply, these days were busy for me