The following it's an explanation of how to generate a 3D binary stereoscopic hologram using Blender and Python from the code attached to this repository. The process is divided into three main processes:
- Sub-images generation using Blender.
- Hogel generation from the sub-images.
- Binary hologram generation.
The ultimate result should be a BMP file which can be printed or used in computational simulations to verify the generated hologram.
A detailed explanation is given in inserte cita chida
Make sure you download all the files, especially the file BinaryStereograhpicHologramFunctions.py which contains all the important functions for hologram generation. Also, check all the requirements mentioned in requirements.txt to avoid having trouble when running the file codes. Also, make sure to verify set up the directories correctly.
The variables the user must be careful of when using all the different file codes are:
- N_in : Number of inches.
- res : Resolution of the printer.
- N_proj_i : Number of vertical projections.
- N_proj_j : Number of horizontal projections.
If these do not coincide in all the files, it may cause errors when compiling the codes. There are some other variables that the user may play around with at their discretion to obtain different results.
Three different files are used to generate the holograms, in each one of them is fundamental to set up correctly the directories so the files that will be generated by the codes can be properly used in each step. It will be stressed in each step to make sure you are aware of how you save your files. In this section, we will explain how the directories were thought to be used, but feel free to change them being aware that it may involve modifying the codes.
- ../DataBase/ : This is where the stl files would be stored and access.
- ../Sub_images/ : This is where the sub-images will be saved after running the codes.
- ../Sub_images/Sub_imagesnxm_0000_object/ : An extra folder will be generated automatically for each different object you want to make a hologram of, and it will be saved with the number of perspectives, the resolution, and the given name of the object. Inside this folder, the individual sub-images will be saved as Sub-imagenm.bmp where n and m correspond to the enumeration of the perspectives.
- ../Transfer Function/ : This is where the npy files of the hogels will be saved and accessed.
- ../Transfer Function bmp/ : This is where the bmp files of the binary holograms will be saved.
Having your folders organized in this way or equivalent should not give you any problems when running the codes.
To generate the sub-images prepare a central scene in Blender (It's highly recommendable to center the scene since the program was built that way). Then in the Scripting tab use the code from SubimageGeneration.py and run it. An important thing is to coincide the name of the variable current_object with the object name in Blender. This program normally works with only one object (as seen in the Example) but if desired make sure you choose one specific object which the camera will follow and make that object part in blender coincide with the name of the variable current_object.
Normally, we would import STL files to the scene and generate the sub-images. That being said all directories must be changed according to the user and if everything is being generated within Blender some parts of the code may be commented on and compiled as usual. The variables that you may want to change are:
- max_abs_azimut : Maximum angle that will be spaned horizontally (by default its set at 48°)
- max_abs_polar : Maximum angle that will be spaned vertically (by default its set at 24°)
NOTE 1: The script from the aforementioned file can be used as a base program and can be modified at the user's desire. The important thing is to capture the desired object from different ordered perspectives.
NOTE 2: The program is built to have a certain order of the directories and name the sub-images if changed, be aware that the results may lead to errors in the compilation.
Once the sub-images are generated, you must compile the file mainHogelGeneration.py which will calculate the hogels for each perspective and return an NPY file with the information of all the hogels stacked in order of perspective in a single matrix. The variables that you may want to change are:
- directorySubimages : Directory to the sub-images generated.
- directoryTransfer : Directory where the npy files will be saved.
- scale : Scaling factor for the perspective of the scene within a single hogel (by default it's set to 0.3 which gave us the best results). The user can input several scaling factors in a vector to obtain different results.
- N_cicles : Number of cycles that the algorithm to generate the hogel will use (by default it's set to 500 which guarantees convergence).
- crop_percentage : A percentage to crop each sub-image from the edges where 0 represents 0% cropping the edges and 1 cropping 100% of the image. A value of 1 for this parameter is won't do anything to the hogel. Change this parameter at your discretion depending on the sub-images.
With the Hogels generated, the last step is to generate the hologram by using the script in the file mainBinaryHologram.py. It is very important to say that especially this script was made to match the equipment that we had access to. So you will notice that this program as it is will work only for resolutions of 2400 or 3600 dpi. This is because part of the process involves using an angle to deviate the diffraction orders from the optical axis, and our tries involved only using these resolutions. This does not mean that our method won't work for other resolutions but that a simulation of the holograms will be needed to adjust the diffraction order positions. The variables that are important for this program are:
- directoryTransfer : Directory where the hogels as a npy file were stored from the previous step.
- directorySubimages : Directory where the subimages generated by the first step were stored.
- directoryTransfer_bmp : Directory where the binary holograms will be stored as a BMP file.
- lambd : The wavelength where the hologram will be tested (In general monochromatic light will yield better results when testing).
- thz : Deviation angle in the z-axis (assuming propagation in the z-axis).
- thxy : Deviation angle as a rotation in the plane-xy.
When working with high resolutions you may notice that the size of the NPY files of the hogels is heavy. In this file there are a few commented lines corresponding to a propagator that can be used to test the holograms generated, since the matrix can be too big, we recommend using another package rather than matplotlib such as rasterio or PyQt5 to see the results. After running this program a BMP file with the binary hologram will be generated, and this file is ready to print.
NOTE: The deviation angles can be constructed in several ways, in this case, the proposal is to use
The following is a brief example of the steps mentioned above showing what you would expect when using this code. In this case, both codes and output files will be provided in this project (see the section External links). The resolution used for this example is 3600 dpi, with 3x8 projections and 5 inches of maximum size.
In the file Subimages.blend there is already available an example of how a scene may look like for the case of a Lego block. The only thing remaining to use this file is to make sure about the directories and press run while in the Scripting tab. You should see something similar to the image below.
Once the program finishes generating the different sub-images you should end up with a folder with files as in the following image where it's indicated the order of each sub-image.
Once you have a folder with all the sub-images, and making sure about the directories where you want to have the hogels generated, run the file mainHogelGeneration.npy and you should end up with NPY files similar to the ones in the image below.
In this case, the program used different scales and hence the three files. But it will depend purely on the number of cases you test.
Finally, the only thing remaining is to generate the holograms using the hogels generated with the code in the file mainBinaryHologram.py, for this, make sure again about the directories, and the other variables mentioned you should end up with a BMP file. That is your binary hologram! and that's ready to print. It does not seem completely binary but this is probably because of the resolution of your screen. In the following image, you can see an example of what you can expect and a zoom-out of a portion. This BMP file will be provided too.
For this example, as mentioned before, we have certain values of the resolution, size, projections, and hence the angles of deviation from the optical axis. Hence that the program is already prepared to generate the hologram, but this may not be the case for other resolution values. One can confirm that the angle values will work by testing them with the commented code provided in the same file. You should end up with a result like the following image.
You know that the angles that you chose will probably work when you see a result like this. Two symmetric diffraction orders that are not near the center and not close to the borders of the image.
NOTE: To run this example from scratch may take a few hours to compile all three steps of the process, and since it's a high resolution plotting the results and making tests may be heavy for the computer.
The following link goes to a Google Drive folder with an example of the setup of the directories including the STL file, sub-images, hogels and holograms generated using the codes provided in this repository. Google Drive