I want to bend an image

9 次查看(过去 30 天)
Mats
Mats 2014-9-23
评论: Mats 2014-9-24
Dear community,
I have this 720x720 image and want to do a spatial transform in a way that a horizontal line will become a U-shape. So depending on the x-coordinate the rotation/translation will be different. Simply put the left side should rotate a bit clockwise and the right side counterclockwise.
Any thoughts?
nParts = 15;
iWidth = size(IM,2)/nParts;
iRotation = (-(nParts-1)/2:(nParts-1)/2)*2;
for iPart = 1:nParts;
K(iPart) = {imrotate(IM(:,iPart*iWidth-
iWidth+1:iPart*iWidth),iRotation(iPart),'bilinear','loose')};
end
This is what I came up with only now the K(i) elements have to be combined, or even better solution would be a single transformation matrix, like:
x' = x*?*cos(t) + y*?*sin(t)
y' = -x*?*sin(t) + y*?*cos(t).
Kind regards,
Mats

采纳的回答

Image Analyst
Image Analyst 2014-9-23
Sorry I don't have time this morning to fix it or complete it for you. See Steve's blog: http://blogs.mathworks.com/steve/2006/08/04/spatial-transformations-defining-and-applying-custom-transforms/ for guidance.
  1 个评论
Mats
Mats 2014-9-24
To let you know, I found the solution with your help yesterday! So it worked.
t = @(x) x(:,1).*-pi/4;
f = @(x) [x(:,1).*cos(t(x))+x(:,2).*sin(t(x)),-x(:,1).*sin(t(x))+x(:,2).*cos(t(x))];
g = @(x, unused) f(x);
tform = maketform('custom', 2, 2, [], g, []);
IM = imtransform(IM, tform, 'UData', [-1 1], 'VData', [-1 1], ...
'XData', [-1 1], 'YData', [-1 1]);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by