how to rotate image using function notation

1 回表示 (過去 30 日間)
mark palmer
mark palmer 2023 年 2 月 7 日
コメント済み: Chris 2023 年 2 月 7 日
How do I write Matlab code using functions to make a rotation on an image? THis is all I've got so far, and I'm probably way off...
I = 'cameraman.jpg';
fa = 45;
f1 = @(xy) xy(:,1) .* cosd(fa) + xy(:,2) .* sind(fa);
f2 = @(xy) -xy(:,1) .* sind(fa) + xy(:,2) .* cosd(fa);
ifcn1 = @(xy) f1(xy);
tform1 = geometricTransform2d(ifcn1);
Rin = imref2d(size(I),[-1 1],[-1 1]);
Rout = imref2d(size(I),[-1 1],[-1 1]);
rho1a = imwarp(I,Rin,tform1,'OutputView',Rout,FillValues=0);

採用された回答

Chris
Chris 2023 年 2 月 7 日
If you're using imwarp, you might as well use imrotate, no? You'd be using the function imrotate() to rotate an image, if that's really your goal.
fa = 45;
I = imread('cameraman.tif');
imrot = imrotate(I,fa);
imshow(imrot)
If you want an anonymous function, like you're using...
rotateImage = @(im, ang) imrotate(im, ang);
imrot = rotateImage(I, fa);
imshow(imrot)
You could also make a standalone function, in a file of the same name or at the bottom of a script, that accepts inputs and outputs the rotated image, and does whatever else you want with the input.
imrot = rotImFun(I, fa);
imshow(imrot);
function out = rotImFun(im, ang)
out = imrotate(im, ang);
end
  3 件のコメント
mark palmer
mark palmer 2023 年 2 月 7 日
編集済み: mark palmer 2023 年 2 月 7 日
IS there an alternate way to do this with trig functions within an anonymous function? I know it isn't the easiest way, I'm just trying to learn.
Chris
Chris 2023 年 2 月 7 日
I'm unaware of a method that doesn't require a complex series of operations, which a single anonymous function isn't really suited for. That doesn't mean it doesn't exist--it just means I don't have an answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by