Asking about the rounding numbers. (Problem with rotating image)
Mostrar comentarios más antiguos
Hi,
the following is my question. With the line [ x-min(min(x))+1 ], x is a matrix, but min(min(x)) is a scalar. How are they subtracted? What is [ x-min(min(x))+1 ]? I don't get the code by other.
I = imread('pout.tif');
theta = 0.25*pi;
R = [cos(theta) -sin(theta);sin(theta) cos(theta)];
for i = 1:size(I,1)
for j = 1:size(I,2)
a = R*[i-1;j-1];
x(i,j)=a(1); %new x
y(i,j)=a(2); %new y
end
end
x=int16(x-min(min(x))+1);%rounded
y=int16(y-min(min(y))+1);%rounded
for i = 1:size(I,1)
for j = 1:size(I,2)
I_new(x(i,j),y(i,j)) = I(i,j);
end
end
subplot(1,2,1); imshow(I);
subplot(1,2,2); imshow(I_new);
2 comentarios
"How are they subtracted?"
It is always possible to perform arithmetic using a scalar and a matrix:
[1,2;3,4]+5
Assuming that x is 2D, then this
x-min(min(x))+1
subtracts the global minimum of x from x. This removes any offset. Since zero is not a valid index, 1 is added. The use of int16() is equivalent to just using round() in this context.
I'm also assuming that you're more concerned with why the very act of rounding the transformed indices is leaving holes in the image. Since you're mapping forward and placing source image pixels in a blank output image, the rounding is bound to mean that some output pixels have no source pixel mapped to them. You can either try mapping in reverse to find the source pixel for each output pixel, or you can use some sort of interpolation instead of direct indexing. The fact that you're making your own image rotation code means that you have some reason for doing so, and likely some corresponding limitations. I don't know what those might be.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre ROI-Based Processing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

