rotated,scaled, and translated image

hi,
i want to apply rotation,scale, and translation (all) in one image.
here is my code:
% reading the image
I=imread('cameraman.jpg');
% rotate the image
deg = -30;
I2 = imrotate(I, deg, 'bilinear', 'crop');
% resize the image(scale)
J=imresize(I,[310 310],'nearest');
% translate the image
T = [1 0 0; 0 1 0;70 70 1];
tform_translate = maketform('affine', T);
[I3,xdata,ydata] = imtransform(I,tform_translate);
% imshow(I3,'XData',xdata,'YData',ydata)
all_adjust=I2+J+I3;
imshow(all_adjust)
axis on
axis([0 400 0 400])
----------------------------------------------------------
but when i combine them i'm gettin' this error:
??? Error using ==> plus
Matrix dimensions must agree.
Error in ==> all at 18
all_adjust=I2+J+I3;
-------------------------------------------
tell me what to do ?????????????????

답변 (1개)

Walter Roberson
Walter Roberson 2012년 2월 5일

0 개 추천

I2 contains a rotated image the same size as the original image (because you used 'crop'), and in I3 you store a resized version of the original image. Now it could happen that what you resized to was exactly the same size as the image already was, but most of the time that will not be the case. Then when you try to add the two images of different sizes together, you are going to have a problem.
Are you trying to produce a single image that has three copies of the original image, one rotated, one resized, one translated? Or are you trying to take the original image and rotate it, resize the rotated image, and then translate the resized (rotated) image? Transformed images do not simply add together in order to produce a single final image; transforms themselves do not simply add together either (you have to use matrix multiplication to chain transforms together.)

댓글 수: 3

lama riad
lama riad 2012년 2월 6일
trying to take the original image and rotate it, resize the
rotated image, and then translate the resized (rotated) image.
Here what i did recently but i don't know how to add the translation parameters in the resizing part,could u help me?
% reading the image
I=imread('cameraman.jpg');
% rotate the image
deg = -30;
I2 = imrotate(I, deg, 'bilinear', 'crop');
% translate the image
T = [1 0 0; 0 1 0;70 70 1];
tform_translate = maketform('affine', T);
[I3 xdata ydata] = imtransform(I2,tform_translate);
% resize the image(scale)
[m map]=imresize(I3,0.7,'nearest');
lama riad
lama riad 2012년 2월 6일
ok thank u i got the desired result
lama riad
lama riad 2012년 2월 6일
% reading the image
I=imread('cameraman.jpg');
% rotate the image
deg = -30;
I2 = imrotate(I, deg, 'bilinear', 'crop');
% resize the image(scale)
I3=imresize(I2,0.7,'nearest');
% translate the image
T = [1 0 0; 0 1 0;70 70 1];
tform_translate = maketform('affine', T);
[I4 xdata ydata] = imtransform(I3,tform_translate);
imshow(I4)
axis on
axis([0 400 0 400])

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

질문:

2012년 2월 5일

편집:

2013년 10월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by