how can I rotate the image ?

조회 수: 2 (최근 30일)
jiji hr
jiji hr 2016년 5월 26일
답변: Image Analyst 2016년 5월 30일
Hello,
I have this function :
function spin = generate_spin_image(vertex, normal, indVertex, med)
%[vertex, faces] = read_off(namefile);
%med = computeMedianEdge(namefile);
%[normal,normalf] = compute_normal(vertex, faces);
binSize = med;
W = 25;
angleSupport = pi/2;
imageWidth = W*binSize;
p = vertex(indVertex,:);
numVertices = size(vertex,1);
%alpha = zeros(numVertices,1);
%beta = zeros(numVertices,1);
spin = zeros(W,W);
TabAlpha_1 = zeros(1,34817);
TabBeta_1 = zeros(1,34817);
for i=1:numVertices
x = vertex(i,:);
if acos(sum(normal(indVertex,:).*normal(i,:))) < angleSupport
alpha = sqrt(sum((x - p).^2) - (sum(normal(indVertex,:).*(x-p))).^2);
beta = sum(normal(indVertex,:).*(x-p));
TabAlpha_1(i) = alpha;
TabBeta_1(i) = beta;
is = floor((imageWidth/2 - beta)/binSize);
js = floor(alpha/binSize);
a = alpha/binSize - js;
b = (imageWidth/2-beta)/binSize - is;
if is >=1 && is <=(W-1) && js >=1 && js <=(W-1)
spin(is,js) = spin(is,js) + (1-a)*(1-b);
spin(is+1,js) = spin(is+1,js) + a*(1-b);
spin(is, js+1)= spin(is,js+1) + (1-a)*b;
spin(is+1,js+1) = spin(is+1,js+1) + a*b;
end
end
end
figure;
TabBeta_1 = TabBeta_1';
TabAlpha_1 = TabAlpha_1';
plot(TabBeta_1, TabAlpha_1, 'ro');
figure;
imagesc(spin');
colormap( flipud(gray) );
In the end I plot the array that contains the projection of the 3D coordinates of a vertex in 2D coordiantes (alpha, beta), and the image spin results from the computation of alpha and beta.
The problem I have is that it gives me this:
It seems to be good but the image (grayscale) is rotated compared to the projection (plot with red points), and I want it to be the same as the plot.
I hop I explained my problem clairly. I would be grateful for any help.

채택된 답변

Image Analyst
Image Analyst 2016년 5월 30일
The top (line 1) of an image is at the top while for a plot it's normally at the bottom. Set the 'ydir' property of the plot to be 'reverse' and they'll both go in the same direction.
plot(......
ax = gca;
ax.YDir = 'reverse';

추가 답변 (1개)

Nut
Nut 2016년 5월 26일
Hi,
I'm not sure but I think that the "view" function could help you:
Alternatively, if you need just a different view, maybe you can solve changing the signs of the coordinates of red points when you plot them.
  댓글 수: 2
jiji hr
jiji hr 2016년 5월 27일
It didn't works becaus if I understood very well, it is for 3D plots, and I have juste a 2D plot.
Any way I found the solution using
imrotate(spinImages.spinIm,180);
And thank you so much for your answer.
Nut
Nut 2016년 5월 30일
Ok, good idea. I thought you need to rotate the red points, not the image. I was misunderstanding, sorry.
Kind regards.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by