Clear Filters
Clear Filters

rotated,scaled, and translated image

1 view (last 30 days)
lama riad
lama riad on 5 Feb 2012
Edited: Matt J on 1 Oct 2013
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 ?????????????????

Answers (1)

Walter Roberson
Walter Roberson on 5 Feb 2012
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 Comments
lama riad
lama riad on 6 Feb 2012
ok thank u i got the desired result
lama riad
lama riad on 6 Feb 2012
% 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])

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!