📜 ⬆️ ⬇️

Stereo image is just

Hi,% username%.

In this article I want to tell you how you can independently create a stereo image using a graphical editor and a small program.
mask image
stereo image

Introduction


First, let's look at how the stereo image is arranged and how to look at it. In the first place, it consists of repeating fragments.
pic 1.
pic 1.
')
It is very important that the width of the repeating fragment be smaller than the distance between the eyes. For a comfortable viewing of the stereo image, the width should vary from 1/3 to 2/3 of this size. The greater the width, the deeper (three-dimensional) image can be obtained. The smaller the width, the less tired the eyes are from viewing the stereo image.

To see a three-dimensional image, it is necessary to focus the view behind the plane of the drawing so that the images for the left and right eyes coincide. For an image entirely composed of repeating fragments, you will observe exactly the same imaginary image (flat plane). The only difference is that it will seem to you that the drawing has become located further.
pic 2.
pic 2.

How is the three-dimensional image?


To make the image more voluminous, some parts of it must be perceived as closer, others as more distant. This effect can be achieved by shifting the image elements.

Figure 3 shows how the virtual image has changed, after shifting two elements (red and purple) of the real image one position to the left.
rice 3.
rice 3.

Two artifacts of the same size were formed on the imaginary image, equal to the size of the shifted elements. An artifact located to the left of the location of the shift is perceived as being located closer to the observer (in front of the plane of the imaginary image). The artifact on the right, on the contrary, is perceived as located behind the plane of the imaginary image. About the position of the elements of the imaginary image, which are simultaneously visible only to one eye (marked with a dotted line), the brain "thinks out" independently.

I note that the shift should not exceed half the width of the repeating part. When the shear size is close to this boundary, it is difficult for the eye to determine whether the observed area is convex or dented.

If we want to depict objects located only in front of the imaginary image plane, we need to be able to deal with unwanted artifacts. To do this, it is sufficient to shift the elements in each period located to the right of the first shift point (Figure 4).
rice 4.
rice 4.

It remains to show how objects with different degrees of distance are formed on the imaginary image. For a visual example, this time we will shift the three elements to the left, but not by one position, but by two. Comparing Figures 4 and 5, we see that in the last figure, due to a shift by a greater number of positions, we obtained an object closer than when shifted by one position.
rice 5.
rice 5.

Actually implementation


A stereo image was created with the following function written in C #:

private Bitmap GenerateStereoPicture(Bitmap bitmapMask) {   //        int w = bitmapMask.Width;   int h = bitmapMask.Height;   int[][] mask = new int[w][];   for (int x = 0; x < w; x++)   {     mask[x] = new int[h];     for (int y = 0; y < h; y++)       mask[x][y] = bitmapMask.GetPixel(x, y).R / 32;   }   // C    int s = 100;   Bitmap stereoImg = GetNewStereoPicture(w + s, h, s);   //      for (int y = 0; y < h; y++)     for (int x = 0; x < w; x++)       if (mask[x][y] > 0)       {         Color pixel = stereoImg.GetPixel(x + mask[x][y], y);         for (int i = x + s; i < w + s; i += s)           stereoImg.SetPixel(i, y, pixel);       }   return stereoImg; } 

At the input, the function accepts the image-mask created in the graphic editor. First, a text label was created, to which a gradient fill was then applied (the very first drawing in the article).

Points of black color are treated by function as points with zero shift, i.e. they form the plane of the imaginary image. The brighter the color of a point, the greater its shift, the closer it will appear to the observer. Since the image is made in gray colors, I used the brightness of the red component of RGB divided by 32 to determine the brightness of the point. Thus, the maximum possible shift is 255/32 = 7.

After forming an array of shifts, the function creates an image with a width of w + s pixels, a height of h pixels and a width of the repeating part s = 100 pixels. As a repeating part, I generate a random image consisting of a random number of random shapes (ellipse, rectangle, arc, curve) of random size and color. You can come to this stage creatively and prepare some beautiful background in advance.

At the final, most important stage, each pixel of the image is shifted in accordance with the shift array.

PS I would be very happy if this article will help someone at least learn how to watch stereo images, since I myself was not immediately able to master it.

Source: https://habr.com/ru/post/127681/


All Articles