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