I wanted to somehow encode information based on the holographic principle. I wanted it for a reason, but to test some of my ideas and theories. Theories were not confirmed, the ideas were not realized. But since I didn’t find such an algorithm, and I had to invent it myself, based on physics textbooks, I decided to share it with Habré. The algorithm, by the way, is quite simple.
So let's get started.
How a hologram is made. In general, a beam of light from a
coherent light source is divided into two parts in one way or another, one of which falls directly on a photographic plate, and the other part also falls on a photographic plate, but after reflection from the object whose hologram we wish to receive. As a result, a picture of the interference of light coming directly from the source and the light reflected from the object is fixed on the photographic plate.
The essence of holography is that in the interference picture not only the brightness of one or another point of the object is encoded, but also the distance to that point. This happens because light waves come to a photographic plate in different phases (and the phase depends on the distance to the object's point), these waves are formed in accordance with their phases, due to which, in fact, the interference pattern is formed.
The image of the object is restored simply by illuminating the developed photographic plate with light of the same wavelength. There are holograms restored by white incoherent light, but they are not considered.
The hologram has interesting properties.
For example, you can restore a full image of an object on any piece of a holographic image (with deterioration of image quality).
It is possible to record images of several objects on one photographic plate using light sources with different wavelengths. And restore the image of each object individually by illuminating the photographic plate with light of the same wavelength that was used to record the desired object.
')
As a matter of fact, the idea of ​​holographic coding came into my head, because I wanted to encode a sound file in this way. It would be possible to cut off any piece of such a file — and to reproduce the entire original sound (in the worst quality) using it. It would be possible to record several sounds into one file, and any piece of the file would contain these sounds that can be played separately.
Why this idea was not realized?
First, the sound is not a picture, we see the picture completely at once, and automatically highlight the familiar details. And we listen to the sound consistently, and any noiseiness greatly impairs perception. Moreover, when holographic coding noise appears in the form of whistles, hisses, etc., overlapping the original sound.
Secondly, I did not immediately take into account the complexity of the algorithm. The complexity of the algorithm is estimated as O (n ^ 2). Those. for encoding (and decoding) a file with a size of 1 megabyte, a trillion (million million) iterations are required, and with each iteration it is also necessary to perform calculations ... For example, the WAV file with a size of 10 kilobytes (2-3 seconds of sound) was encoded for about a minute (10,000 * 10,000 iterations = 100 million iterations). And speed up the algorithm does not work. And to encode a file 10 times larger will take 100 times longer.
And in the third - for obtaining a normal holographic image it is required that the object be a contrast. And what is the contrast in the sound file? Almost random set of numbers.
But back to the algorithm itself, and its working demonstration.
Coding and decoding are performed by the same algorithm, but during decoding a couple of coefficients change.
The test image processing algorithm was implemented in PHP, because “this is faster” (the C language was used to experiment with the WAV file).
Initially: the brightness matrix of the pixels of the original image (for encoding or decoding, you will need 2500 * 2500 = about 6 million iterations, in my case - a few seconds of PHP)
$ data0 [50] [50];
Output: pixel brightness matrix "on a photographic plate"
$ data1 [50] [50];
$W=0.1; //
//
for($x1=0;$x1<50;$x1++)
for($y1=0;$y1<50;$y1++) {
// - ,
256 , , (128 ).
$px=128.0; // , (.. =0 )
// -
for($x0=0;$x0<50;$x0++)
for($y0=0;$y0<50;$y0++) {
// (x0;y0) (x1;y1) z=1,
$D=sqrt(1+($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1));
//
$Phase=$D/$W;
// ( 0.3 - )
$obj_light=($data[$x0][$y0])*0.3;
// ( )
$px+=$obj_light*cos($Phase);
}
// , .
$px=abs($px);
// - (x1;y1)
data1[$x1][$y1]=$px;
}
The coefficient in this line is $ obj_light = ($ data [$ x0] [$ y0]) * 0.3; is selected. Although it is possible to derive a formula for it, though separately for the case of coding and the case of decoding.
Decoding is performed by the same algorithm, only $ px = 128.0; changes to $ px = 0.0; (in this case, the image is restored only from the reflected light)
Well, the results of the work.
Source image

Recorded hologram and image restored by it


The hologram recording erased on 1/3 and the image restored on it


The hologram recording erased by more than 2/3 and the image reconstructed from it


For the case of three points and the wavelength of light radiation W = 1, an example is
here .
There are two reasons for strong noises:
- In the experiment, the brightness of the points are rounded to integers in the range 0..255. Some of the information is lost in the dropped fractional parts, and the range, of course, is too small.
- Small area hologram, only 50 to 50 points. This is much less than a square millimeter of a true hologram. In reality, photographic materials with a resolution of 5,000 lines / mm are used to obtain a hologram.
If the three-dimensionality of the hologram is needed, this will not complicate the algorithm, since it will be enough to change the formula for calculating the distance D (now the hologram is flat, the Z coordinate is always = 1)
Here is such an experiment.