Search code examples
matlabcolor-depth

read and show raw depth image in matlab


I have a set of .raw depth images. The image format is 500X290 with 32 bytes per pixel. When I open them with IrfanView image viewer I see the depth image correctly like this: displayed image in IrfanView

Now I want to read and display the same depth image in Matlab. I do like this:

 FID=fopen('depthImage.raw','r');
 DepthImage = fread(FID,[290,500],'bit32');
 fclose(FID);
 colormap winter;
 imshow(DepthImage);

DepthImage is a 290X500 type double matrix. what I get from this code is this image: displayed image in Matlab viewer

when I change fread parameter from 'bit32' to 'bit24' I get this: displayed image in Matlab with bit24

I guess each element in DepthImage contains 32 bits where each 8 bits corresponds to R,G,B and D values. but how can I read the image correctly and display it like the one in IrfanView?

the raw file: https://drive.google.com/file/d/1aHcRmMKvi5gtodahR5l_Dx8SbK_920c5/view?usp=sharing


Solution

  • There might be an issue with image metadata header, like "date and time of the shot", "camera type". Open your image with notepad++ to check for "date and time". If you upload your original raw image, it will be easier to try things.

    Upd: Ok, this is something. Check if it helps

     FID=fopen('camera00000000000014167000.raw','r');
     DepthImage = fread(FID,290*500*4,'int8');
     DepthImageR = DepthImage(1:4:end);
     DepthImageG = DepthImage(2:4:end);
     DepthImageB = DepthImage(3:4:end);
     DepthImageD = DepthImage(4:4:end);
    
     dataR = reshape(DepthImageR, 500,290);
     dataG = reshape(DepthImageG, 500,290);
     dataB = reshape(DepthImageB, 500,290);
     dataD = reshape(DepthImageD, 500,290); % all equal to 64 - useless
    
     figure()
     subplot(2,2,1)
     image(dataR)
     subplot(2,2,2)
     image(dataG)
     subplot(2,2,3)
     image(dataB)
     subplot(2,2,4)
    
     data = zeros(500,290,3);
     data(:,:,1) = dataR;
     data(:,:,2) = dataG;
     data(:,:,3) = dataB;
    
     image(data)