MATLAB Answers

0

Image from a double precision matrix

Asked by VISWANATH on 10 Aug 2011
Dear all
I am trying to implement a phase map of set of 4 images with following steps.
i1_8B=imread('C:\image1.bmp');
i1=double(i1_8B);
i2_8B=imread('C:\image2.bmp');
i2=double(i2_8B);
i3_8B=imread('C:\image3.bmp');
i3=double(i3_8B);
i4_8B=imread('C:\image4.bmp');
i4=double(i4_8B);
PSImage=atan2(i4-i2,i1-i3);
image(PSImage);
colormap(gray);
imwrite(PSImage,'phase.bmp');
The code works well, but when i read image again after saving, the dimentions are 342×433×3(matrix)instead of 342×433. I know that colormap command gives m×n×3 matrix for image when it is read. How can i remove this extra ×3 dimension??? I still want the same image with 342×433.

  0 Comments

Sign in to comment.

1 Answer

Answer by Friedrich
on 10 Aug 2011

Hi,
when deletung the 3rd dimension it gets a grayscale image. To do this you can use the rgb2gray function, e.g
imwrite(rgb2gray(PSImage),'phase.bmp');

  4 Comments

Show 1 older comment
Friedrich
on 10 Aug 2011
Lets say the Matrix is called X, than do
gray_image = uint8( ( (X + pi)/(2*pi) ) * 255 )
I tried the you suggestion Friedrich, but looks like some information from images is lost. I used to see some fringes in subtracted image say (A-B) before now i can not see them any more. Where A image of arctan avalues of set 1, B is image arctan values of set 2.
Any further ideas?
Friedrich
on 10 Aug 2011
The formula was for the above example. In general you have to shift the values to [0,1] interval and than multiply it with 255. In general the formula should look like this
gray_image = uint8( ( (X - min(min(X)))/(abs(min(min(X))) + max(max(X)) ) ) * 255 )

Sign in to comment.