Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Principle axis

arifmuhammad36arifmuhammad36 MalaysiaMember Posts: 1

CAn any one help me in this code, i want to draw the principle axis, every things are ok but lines aare not visualized.
code is given below.
[FileName,PathName] = uigetfile('.bmp');
I = double(imread([PathName '\' FileName]));
% normalize between 0 and 255
bw=~im2bw(I,0.5); %Threshold and invert
subplot(1,2,1), imshow(bw,[]);
[y,x]=find(bw>0.5); %Get coordinates of non zero pixels
centroid=mean([x y]); %Get (centroid) of data
hold on; plot(centroid(1),centroid(2),'rd'); %Plot shape centroid
C=cov([x y]); %Calculate covariance of coordinates
[U,S]=eig(C)
m=U(2,1)./U(1,1);
const=centroid(2)/m.
centroid(1);
xl=50:450; yl=m.xl+const
subplot(1,2,2), h1=line(xl,yl); %Display image and axes
set(h,'Color',[1 0 0],'LineWidth',2.0)
m2=U(2,2)./U(1,2);
const=centroid(2)/m2.
centroid(1);
x2=50:450; y2=m2.*x2+const
h2=line(x2,y2);
set(h,'Color',[1 0 0], 'LineWidth',2.0),

Sign In or Register to comment.