Forward mapping- problem with Rotation
Afficher commentaires plus anciens
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?

Réponses (1)
Matt J
le 19 Jan 2018
You should probably just do
output_image = imwarp(input_image,affine2d(matrix));
10 commentaires
Kamil Galazka
le 19 Jan 2018
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
le 19 Jan 2018
This should fix all that.
[x, y] = transformPointsForward(affine2d(matrix), U(:),V(:));
Kamil Galazka
le 19 Jan 2018
Matt J
le 19 Jan 2018
Could you attach input_image in a .mat file
Kamil Galazka
le 19 Jan 2018
Matt J
le 19 Jan 2018
For me it runs with no problems, and produces the desired result.
Kamil Galazka
le 19 Jan 2018
Matt J
le 20 Jan 2018
I think you're getting the right image, but just displaying it incorrectly,
imshow(output_image/max(output_image(:)))
Catégories
En savoir plus sur Image Processing Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


