1

I have extracted the depth map of 2 images and stored them as .tif file

now I would like to use openGL to join these two images depending on their depth

so I want to read the depth for each image from the .tif file and then use that depth to draw the pixel with the higher depth

to make it more clear the depth map are two images like this link

so say I have the pervious image and I want to join it with this image

link

my question is how to read this depth from the .tif file

Lily
  • 816
  • 7
  • 18
  • 38
  • What do you mean by "depth map"? Are these actual depth buffers taken from somewhere or just height maps? – Nicol Bolas Oct 18 '12 at 20:11
  • they are gray-images that represent the depth of the picture I generated them using paraview and python, so I want now to read these pictures which are in .tif extension to get the depth values and then join the two images – Lily Oct 18 '12 at 20:17
  • @NicolBolas see the original question I have added some explanation of wat I exactly want – Lily Oct 18 '12 at 20:33

1 Answers1

2

Ok, I'll have a go ;-)

I see the images are just grayscale, so if the "depth" information is just the intensity of the pixel, "joining" them may be just a matter of adding the pixels. This is generally referred to as "blending", but I don't know what else you could mean.

So, you need to;

  1. Read the 2 images into memory
  2. For each pixel (assuming both images the same size):
    • read the intensity from image A[row,col]
    • read the intensity from image B[row,col]
    • write max(A[row,col],B[row,col]) to C[row,col]
  3. Save image C - this is your new "joined" image.

Now OpenGL doesn't have any built-in support for loading/saving images, so you'll need to find a 3rd party library, like FreeImage or similar.

So, that's a lot of work. I wonder if you really want an OpenGL solution or are just assuming OpenGL would be good for graphics work. If the algorithm above is really what you want, you could do it in something like C# in a matter of minutes. It has built-in support for loading (some formats) of image file, and accessing pixels using the Bitmap class. And since your created this images yourself, you may not be bound the the TIFF format.

Mark Stevens
  • 2,366
  • 14
  • 9
  • "draw the pixel with the **higher** depth"...sounds like the OP wants `max()`, not `sum()`. – genpfault Oct 19 '12 at 19:42
  • @MarkStevens thanks a lot for the answer, and ya I assumed opengl has a support so my question is, is there a way to know the value of the image ? i mean enable to compare the 2 pixels I should know the value of the intensity for that pixel – Lily Oct 20 '12 at 07:54
  • @Lily: yes, but it depends on what library/function you use to load the image. if you want to stay with TIFF, it looks like http://www.libtiff.org/libtiff.html does it, but maybe you could just save your output as bmp or jpeg? In any case, when you load it into memory, you end up with an array of color values, usually represented by 3 bytes - one for red, one for green and one for blue. With grayscale, they would all be the same. You could also just have 1 byte per pixel - it all depends on how it was saved. The values range from 0 for black to 255 for white, just compare the 2 numbers. – Mark Stevens Oct 20 '12 at 15:13