I'm working with an image of an array where we on one side has added an extra row, this in order to make the data scatter greater in one direction. Now I want to rotate the image I my idea is to use PCA. I started off with preprocess the image, segment it and then I only keep the array part for the PCA.
[I, J] = find(ims);
mat = [I, J];
covariance = cov(mat);
[eigvect, eigval] = eig(covariance);
% Chose the eigenvector with highest eigenvalue
if (max(eigval(:,1)) > max(eigval(:,2)))
v = eigvect(:,1);
else
v = eigvect(:,2);
end
v1 = v./norm(v,1);
v2 = [0,1];
%Calculate angle
angle = acosd( dot(v1,v2) / (v1 * norm(v2)) );
My questions are:
- Is it better to use the original grayscale image and perform the PCA on it rather than the binary image?
- Am I wrong using cov instead of pca? My chose is based on the fact that I will eventually change to openCV and implement everything in a smartphone application so I want to use methods that I can find in openCV too.
- Why do I get two angles when I only want the angle between the eigenvector and the vertical vector [0,1]?
- Do you think I should add an extra element to my array in order to increase the difference in how the data is spread?
Thanks for your time :)
Aucun commentaire:
Enregistrer un commentaire