MATLAB Answers

felix
0

registration of pictures using intensities

Asked by felix
on 11 Jul 2012
i have given a picture which is saved up as .tif. the dimension of this picture is 512x512. The picture is valued as uint8. This picture will be translated in x and y direction as well as rotated.now i want to save it up as .tif again or jpg., because i dont want to loose any quality (intensities) of that picture. When i instead use .bmp the quality will be much less.
My problem is: if i use .tif or .jpg to save it up and afterwards i use I=imread('....tif') to load it up, then the pictures value shows up as 512x512x3 3-D.
my goal is it to have the translated and rotated picture as 512x512 2- D and not 3-D after using I=imread ('...').
Thank you for you help!!=)))

  0 Comments

Sign in to comment.

2 Answers

Answer by Sean de Wolski
on 11 Jul 2012
 Accepted Answer

What size is the image you are writing and how are you writing it?
Using *.tif does not add two extra channels for me. Consider:
imwrite(magic(50),'test.tif');
size(imread('test.tif'))

  1 Comment

to hopefully explain my problem better i start from new again. I have 2 different m-files. the picture has a size of 256x256 unit8 (i use a new picture now). in the first m-file i translate a picture named MRI.tif in x and y direction and i also rotate it. after completing that i want to save it up as png or tif or jpg. this picture is now called moved.tif or moved.jpg ... .
in the second m-file i want to use the moved.tif or... . I load it up with imread. now it says 256x256x3 unit8.
here first m-file:
clear all
close all
%I=imread('MRI.tif');% I moving Image
%% %Translation
alpha=0.6; dx = -25; dy = 20;
%Rotation in the center of the picture
[N, M] = size(I);
dm = -N/2;
dn = -M/2;
T1 = [1 0 dm; 0 1 dn; 0 0 1];
T = [cos(alpha*pi) -sin(alpha*pi) dx; sin(alpha*pi) cos(alpha*pi) dy; 0 0 1];
dm = N/2;
dn = M/2;
T3 = [1 0 dm; 0 1 dn; 0 0 1];
I = projective_transform(I, T3*T*T1);
figure;
f=imshow(I,[]);
%%function projective_transform
function ID = projective_transform(I, T)
[N, M] = size(I);
[XI, YI] = meshgrid(1:N, 1:M);
HTK(1, :) = reshape(XI', [1, N*M]);
HTK(2, :) = reshape(YI', [1, N*M]);
HTK(3, :) = ones(1, N*M);
HSK = inv(T) * HTK;
HSK = HSK ./ repmat(HSK(3, :), [3, 1]);
ID = reshape( interp2(XI, YI, im2double(I)', HSK(1, :), HSK(2, :), 'linear', 0), [N, M] );
ID = ID - min(ID(:));
ID =uint8(round( ID ./ max(ID(:)) .* 255 ));
thank you for your help=))

Sign in to comment.


Answer by Image Analyst
on 11 Jul 2012

I think you're confused. JPG will save as compressed and you will lose quality. TIFF and BMP are uncompressed and don't lose any quality. JPEG2000 has a lossless compression mode. But I recommend what many (most) people are using these days and that is PNG. It has lossless compression and therefore no loss of quality. It should not add or subtract any color planes when you save it.

  1 Comment

to hopefully explain my problem better i start from new again. I have 2 different m-files. the picture has a size of 256x256 unit8 (i use a new picture now). in the first m-file i translate a picture named MRI.tif in x and y direction and i also rotate it. after completing that i want to save it up as png or tif or jpg. this picture is now called moved.tif or moved.jpg ... .
in the second m-file i want to use the moved.tif or moved.jpg. I load it up with imread. now it says 256x256x3 unit8.
here first m-file:
clear all
close all
%I=imread('MRI.tif');% I moving Image
%% %Translation
alpha=0.6; dx = -25; dy = 20;
%Rotation in the center of the picture
[N, M] = size(I);
dm = -N/2;
dn = -M/2;
T1 = [1 0 dm; 0 1 dn; 0 0 1];
T = [cos(alpha*pi) -sin(alpha*pi) dx; sin(alpha*pi) cos(alpha*pi) dy; 0 0 1];
dm = N/2;
dn = M/2;
T3 = [1 0 dm; 0 1 dn; 0 0 1];
I = projective_transform(I, T3*T*T1);
figure;
f=imshow(I,[]);
%%function projective_transform
function ID = projective_transform(I, T)
[N, M] = size(I);
[XI, YI] = meshgrid(1:N, 1:M);
HTK(1, :) = reshape(XI', [1, N*M]);
HTK(2, :) = reshape(YI', [1, N*M]);
HTK(3, :) = ones(1, N*M);
HSK = inv(T) * HTK;
HSK = HSK ./ repmat(HSK(3, :), [3, 1]);
ID = reshape( interp2(XI, YI, im2double(I)', HSK(1, :), HSK(2, :), 'linear', 0), [N, M] );
ID = ID - min(ID(:));
ID =uint8(round( ID ./ max(ID(:)) .* 255 ));
thank you for your help=))

Sign in to comment.