Image from a double precision matrix

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.

Respuestas (1)

Friedrich
Friedrich el 10 de Ag. de 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 comentarios

VISWANATH
VISWANATH el 10 de Ag. de 2011
I get error using your suggestion
??? Error using ==> rgb2gray>parse_inputs
MAP must be a m x 3 array.
Error in ==> rgb2gray at 35
X = parse_inputs(varargin{:});
Anobody has idea how to create a gray image from a matrix which has -ve and +ve elements in it. Range of elements is between [-pi, +pi].
for eample part of the matrix looks like
1.2490 2.4980 0.7853
2.7367 -2.0344 -1.5707
2.6779 -2.6011 -1.5707
-1.2490 -2.0344 -1.8157
3.1415 0 -0.4636
Friedrich
Friedrich el 10 de Ag. de 2011
Lets say the Matrix is called X, than do
gray_image = uint8( ( (X + pi)/(2*pi) ) * 255 )
VISWANATH
VISWANATH el 10 de Ag. de 2011
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
Friedrich el 10 de Ag. de 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 )

Iniciar sesión para comentar.

Categorías

Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Ag. de 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by