how can I rotate the image ?

1 Ansicht (letzte 30 Tage)
jiji hr
jiji hr am 26 Mai 2016
Beantwortet: Image Analyst am 30 Mai 2016
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 30 Mai 2016
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';

Weitere Antworten (1)

Nut
Nut am 26 Mai 2016
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 Kommentare
jiji hr
jiji hr am 27 Mai 2016
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 am 30 Mai 2016
Ok, good idea. I thought you need to rotate the red points, not the image. I was misunderstanding, sorry.
Kind regards.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by