Forward mapping- problem with Rotation

3 views (last 30 days)
Kamil Galazka
Kamil Galazka on 19 Jan 2018
Commented: Matt J on 20 Jan 2018
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?

Answers (1)

Matt J
Matt J on 19 Jan 2018
You should probably just do
output_image = imwarp(input_image,affine2d(matrix));
  10 Comments
Kamil Galazka
Kamil Galazka on 19 Jan 2018
Maybe that's a problem with my Matlab version (2015b)... Cause this code is working, but I'm getting this from input_image as jpg:
I think I'll give up, thanks for your help, man :)
Matt J
Matt J on 20 Jan 2018
I think you're getting the right image, but just displaying it incorrectly,
imshow(output_image/max(output_image(:)))

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!