I have an image. I need to identify the axis along which the variance of the image is the smallest. A bit of reading and searching led me to the conclusion that Principal Component Analysis(PCA) is the best alternative. Can anyone help me with orienting the image with respect to its principal axis? Since i am recently introduced to matlab i find it a bit difficult. An example of the image is below. I am trying to rotate the image so that i can generate the histogram.
I haven't used PCA as yet my current code is as shown below
enter code here
I2='image'
I11= bwlabel(I2);
OBB = imOrientedBox(I11);
obbsize=[];
for i=1:size(OBB,1)
obbsize=[obbsize,OBB(i,3)*OBB(i,4)];
end
[a,i]=max(obbsize);
I11=(imrotate(I2,OBB(i,5)));
imshow(I11,[])
[pks,locs] =findpeaks(sum(I11,2));
[M1,Indx1] = max(pks);
imshow(I11(1:locs(Indx1),1:size(I11,2)),[])