Forward mapping- problem with Rotation
显示 更早的评论
So, i got the input image and I want to apply rotation by 60 degrees. Earlier I created the matrix of output image (all of its pixels are the same colour):
matrix=[0.5 0.86603 0; -0.86603 0.5 0; 0 0 1];
u=1:size(input_image,2);
v=(1:size(input_image,1))';
[U,V]=meshgrid(u,v);
t=1:size(input_image,2)*size(input_image,1);
[x, y] = transformPointsForward(affine2d(matrix),U(t),V(t));
%making indices positive integers
min_x=min(min(x));
min_y=min(min((y));
x=ceil(x-min_x+1);
y=ceil(y-min_y+1);
%copying pixels from input to output image
output_image(y(t),x(t),:)=input_image(V(t),U(t),:);
When it comes to scaling, the result is what it should be. But when I use ratation matrix, the result is like below. Is it the error in the way I'm indexing in my last line of code?

回答(1 个)
Matt J
2018-1-19
You should probably just do
output_image = imwarp(input_image,affine2d(matrix));
10 个评论
Kamil Galazka
2018-1-19
I see. Then I think you really want
matrix=[0.5 0.86603 0; -0.86603 0.5 0; 0 0 1];
input_image=permute(input_image,[2,1,3]);
[mm,nn,pp]=size(input_image);
u=1:mm; v=1:nn;
[U,V]=ndgrid(u-mean(u),v-mean(v));
[x, y] = transformPointsForward(affine2d(matrix), U(:),V(:));
%making indices positive integers
min_x=min(x);
min_y=min(y);
x=ceil(x-min_x+1);
y=ceil(y-min_y+1);
max_x=max(x);
max_y=max(y);
idx=sub2ind([max_x,max_y], x,y);
output_image=zeros(max_x,max_y,pp);
for i=1:pp
tmp=zeros(max_x,max_y);
tmp(idx)=input_image(:,:,i);
output_image(:,:,i)=tmp;
end
output_image=ipermute(output_image,[2,1,3]);
Kamil Galazka
2018-1-19
This should fix all that.
[x, y] = transformPointsForward(affine2d(matrix), U(:),V(:));
Kamil Galazka
2018-1-19
Matt J
2018-1-19
Could you attach input_image in a .mat file
Kamil Galazka
2018-1-19
Matt J
2018-1-19
For me it runs with no problems, and produces the desired result.
Kamil Galazka
2018-1-19
Matt J
2018-1-20
I think you're getting the right image, but just displaying it incorrectly,
imshow(output_image/max(output_image(:)))
类别
在 帮助中心 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


