Create a CGH for branching a laser in Python (laser and SLM required)

Introduction

Do you want to laser branch? I want to let you. I will teach you how to branch a laser that anyone can do.

Target audience You can buy a laser, but you find it difficult to process with just one laser

Prerequisites / Knowledge

It's easy to write. Please forgive me for the lack of rigor.

You are trying to branch the laser. The laser is light. Light is a wave. Since it is a wave, it has amplitude and phase. The optical lens has a Fourier transform effect. In short, think that the light that has passed through the lens will be in a Fourier transformed state. (If you are interested, this is easy to understand: https://hoshistar81.jp/pdf/111111doc.pdf).

You know the amplitude of the original laser. Also, it has already been decided what kind of amplitude the laser should have after passing through the lens.

principle

Now you shoot the laser in some phase and hope it's in the desired shape once it's passed through the lens. However, I do not know what phase the laser should be in to achieve the desired shape (amplitude) after passing through the lens. There is a ** iterative Fourier transform method ** as a way to know this ** "what phase should be" **.

The information you have now

--Laser amplitude before passing through the lens --Laser amplitude after passing through the lens (shape of your choice) --The fact that passing through a lens is equivalent to the Fourier transform

is.

Now, let a be before passing through the lens and b be after passing through the lens. Then, it can be said that b seen from a is after the Fourier transform, and a seen from b is after the inverse Fourier transform.

Set the amplitude in region a to the original laser amplitude. The phase is set with some random value (only at the beginning). Fourier transform it (lens transmission from a to b). Set the amplitude in the b region to the desired amplitude. The phase is set with the passed value as it is. Inverse Fourier transform (lens transmission from b to a). Set the amplitude in region a to the original laser amplitude. The phase is set with the passed value as it is.

Do this all the time. Then, the phase is optimized according to the amplitude before and after the Fourier transform. This is the Fourier iterative method. As the name suggests, it's a simple method that simply repeats the Fourier transform and the inverse transform.

スクリーンショット 2020-12-16 3.53.57.png

Implementation

If you implement this in Python, it will look like the following code.


import cv2
import numpy as np
import matplotlib.pyplot as plt


def check_uniformity(u_int, target):
    u_int = u_int / np.max(u_int)
    maxi = np.max(u_int[target==1])
    mini = np.min(u_int[target==1])
    uniformity = 1 - (maxi-mini)/(maxi+mini)
    print("Uniformity:", uniformity)
    return uniformity

def normalization(origin):
    maxi = np.max(origin)
    mini = np.min(origin)
    norm = ((origin - mini) / (maxi - mini))
    return norm


def hologram(phase):
    phase = np.where(phase<0, phase+2*np.pi, phase)
    p_max = np.max(phase)
    p_min = np.min(phase)
    holo = ((phase - p_min)/(p_max- p_min)) * 255
    holo = holo.astype("uint8")
    return holo


def reconstruct(norm_int):
    rec = norm_int * 255
    rec = rec.astype("uint8")
    return rec
    
def main():
    target = cv2.imread("img/target.bmp",0)
    cv2.imshow("target",target)
    cv2.waitKey(0)
    
    height, width = target.shape[:2]
    
    target = target / 255
    laser = 1
    phase = np.random.rand(height, width)
    u = np.empty_like(target, dtype="complex")
    
    iteration = 20
    uniformity = []
    
    for num in range(iteration):
        u.real = laser * np.cos(phase)
        u.imag = laser * np.sin(phase)
        
        #-------lens---------
        u = np.fft.fft2(u)
        u = np.fft.fftshift(u)
        #-------lens---------
        
        u_abs = np.abs(u)
        u_int = u_abs ** 2
        norm_int = normalization(u_int)
        
        uniformity.append(check_uniformity(u_int,target))
        
        phase = np.angle(u)
        
        u.real = target * np.cos(phase)
        u.imag = target * np.sin(phase)
        
        #-----lens---------
        u = np.fft.ifftshift(u)
        u = np.fft.ifft2(u)
        #-------lens---------
        
        phase = np.angle(u)
    
    
    holo_name = "holo"
    rec_name = "rec"
    
    holo = hologram(phase)
    cv2.imwrite("img/{}.bmp".format(holo_name), holo)
    cv2.imshow("Hologram", holo)
    cv2.waitKey(0)
    
    rec = reconstruct(norm_int)
    cv2.imwrite("img/{}.bmp".format(rec_name), rec)
    cv2.imshow("Reconstruction", rec)
    cv2.waitKey(0)
    
    plt.figure(figsize=(8,5))
    plt.plot(np.arange(1,iteration+1),uniformity)
    plt.xlabel("Iteration")
    plt.ylabel("Uniformity")
    plt.ylim(0,1)
    
if __name__ == "__main__":
    main()

Here, suppose that the laser before the lens transmission has a uniform intensity, and that the laser after the lens transmission should branch to 10 × 10 points as shown in the image ( Original image link ). スクリーンショット 2020-12-16 3.51.25.png

The following phase image can be obtained by executing the program under the above conditions. スクリーンショット 2020-12-16 4.04.17.png

This is called ** CGH (Computer Hologram) **. (Please note that the name hologram is used for other purposes in the field of light. It is very confusing.)

This CGH is displayed on a device called ** SLM ** that can control the phase of light as shown in the image, and when the laser is applied to it and passed through the lens, the laser branches into the shape that I wanted. There will be. Troublesome processing can be completed in an instant! スクリーンショット 2020-12-16 4.10.47.png

By the way, rec on the program is the result of reconstruction on the simulation when this CGH is used. Uniformity represents the intensity uniformity of each branched point of this reconstruction result. I wanted all the lasers branched into 10x10 to have the same intensity this time, but if you look at the Uniformity and the reconstruction results, you can see that this is not the case (Uniformity after a certain number of repetitions). Will be saturated). In fact, using the created CGH does not make it as uniform as the reconstructed image.

Although not introduced this time, various methods such as ** weighting algorithm ** have been devised to improve this uniformity. If you are interested, please check it out as well.

At the end

You who had to draw a number of lines with a laser or had to make a lot of holes, which was a hassle! By all means, use the CGH obtained by this Fourier iterative method to branch the laser!

By the way, I don't have any equipment, but those who want to try this method! Is the laser 30 million? Is SLM 300,000 yen? It should have been sold for about, so please buy it and give it a try! That concludes my article!

If you read this article and thought it was "interesting" or "learned", please leave a comment on Twitter, facebook, or Hatena Bookmark! In addition to the blog articles, the official DeNA Twitter account @DeNAxTech also publishes presentation materials at various study sessions. Please follow us!

Recommended Posts

Create a CGH for branching a laser in Python (laser and SLM required)
Create a dictionary in Python
Create a child account for connect with Stripe in Python
Create a DI Container in Python
Create a binary file in Python
Create a Kubernetes Operator in Python
Create a random string in Python
Create and read messagepacks in Python
Parse the Researchmap API in Python and automatically create a Word file for the achievement list
Create a Python environment for professionals in VS Code on Windows
Create a striped illusion with gamma correction for Python3 and openCV3
Create a simple GUI app in Python
Let's create a virtual environment for Python
Create a JSON object mapper in Python
Get a token for conoha in python
[GPS] Create a kml file in Python
Build a lightweight server in Python and listen for Scratch 2 HTTP extensions
Create a Vim + Python test environment in 1 minute
Organize python modules and packages in a mess
Create a GIF file using Pillow in Python
Create a LINE BOT with Minette for Python
I want to create a window in Python
Create a standard normal distribution graph in Python
How to create a JSON file in Python
Automatically create word and excel reports in python
I wrote a class in Python3 and Java
Create a virtual environment with conda in Python
Create a simple momentum investment model in Python
Create a new page in confluence with Python
Create a datetime object from a string in Python (Python 3.3)
Create a package containing global commands in Python
Create a Mac app using py2app and Python3! !!
Create a MIDI file in Python using pretty_midi
Create a loop antenna pattern in Python in KiCad
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Create a Python image in Django without a dummy image file and test the image upload
Create a Django project and application in a Python virtual environment and start the server
Rock-paper-scissors poi in Python for beginners (answers and explanations)
Automate background removal for the latest portraits in a directory with Python and API
Create a data collection bot in Python using Selenium
Create your own Big Data in Python for validation
Create a Python module
[Python] Measures and displays the time required for processing
Create SpatiaLite in Python
[LINE Messaging API] Create a rich menu in Python
[Python] 2 Create a risk-return map for your asset portfolio
[GCF + Python] How to upload Excel to GCS and create a new table in BigQuery
Create a plugin to run Python Doctest in Vim (2)
Preferences for playing Wave in Python PyAudio and PortAudio
Try searching for a million character profile in Python
Problems and countermeasures for Otsu's binarization overflow in Python
Create a plugin to run Python Doctest in Vim (1)
In Python, create a decorator that dynamically accepts arguments Create a decorator
Create a Layer for AWS Lambda Python with Docker
Get stock prices and create candlestick charts in Python
Create a Python environment
Recursively search for files and directories in Python and output
Create a decent shell and python environment on Windows
Create a fake Minecraft server in Python with Quarry
Set a proxy for Python pip (described in pip.ini)
Create a script for your Pepper skill in a spreadsheet and load SayText directly from the script