how can I rotate the image ?
4 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Image Analyst
on 30 May 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';
0 Comments
More Answers (1)
Nut
on 26 May 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 Comments
Nut
on 30 May 2016
Ok, good idea. I thought you need to rotate the red points, not the image. I was misunderstanding, sorry.
Kind regards.
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!