フィルターのクリア

rotated,scaled, and translated image

1 回表示 (過去 30 日間)
lama riad
lama riad 2012 年 2 月 5 日
編集済み: Matt J 2013 年 10 月 1 日
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 日
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 日
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])

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by