Major axis and minor axis

How can I plot the major axis and minor axis for an object in an image?

2 Kommentare

Pamela
Pamela am 1 Sep. 2012
I need your held please !!
Image Analyst
Image Analyst am 10 Nov. 2012
I've just added a section on "How do I create an ellipse" to the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_an_ellipse.3F so that might help you.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 27 Aug. 2012

0 Stimmen

regionprops() to get the centroid and orientation (angle). After that it becomes straight trig. The axes length is R, compute R*cos(theta), R*sin(theta), and center those displacements on the centroid.

17 Kommentare

Pamela
Pamela am 29 Aug. 2012
Bearbeitet: Pamela am 29 Aug. 2012
i tried this. Can you help me to complete it please??
img_seg=segmentation(image);
a = regionprops(img_seg, 'Orientation', 'MajorAxisLength', 'MinorAxisLength', 'Centroid');
theta = pi*a.Orientation/180;
x=a.MajorAxisLength*cos(theta);
y=a.MinorAxisLength*sin(theta);
Pamela
Pamela am 29 Aug. 2012
How can i excute this with an image (black background and a color region of interest)
Image Analyst
Image Analyst am 1 Sep. 2012
I think Steve's blog that Teja referred you to spells it out pretty explicitly. Can't you follow that? Do you want something different than that, like lines instead of ellipses?
Pamela
Pamela am 1 Sep. 2012
Bearbeitet: Pamela am 1 Sep. 2012
I tried it but i had this error
??? Error using ==> iptcheckinput Function REGIONPROPS expected its first input, L, to be integer-valued.
You must have a very old version of MATLAB. Try labeling your binary image before passing it in, instead of passing in just the binary image:
labeledImage = bwlabel(img_seg);
measurements = regionprops(labeledImage, 'Orientation', 'MajorAxisLength', 'MinorAxisLength', 'Centroid');
Pamela
Pamela am 1 Sep. 2012
thx it works but if i want to draw the major axes and the minor axes and to hide the ellipse, what should i do??
Image Analyst
Image Analyst am 1 Sep. 2012
Bearbeitet: Image Analyst am 1 Sep. 2012
Use the centroid, orientation, and the two lengths and some simple 10th grade trigonometry (see Walter's response) to find the endpoints of the lines and then use line() to draw the major and minor axes. The angle for the minor axes will be the major axis angle + 90 degrees. There are degree versions of sin and cos called sind() and cosd() if you prefer to work in degrees instead of radians. IMPORTANT NOTE: the axes are determined by an elliptical fit so don't expect the endpoints of the axes to exactly hit the boundary of the object.
Pamela
Pamela am 2 Sep. 2012
Bearbeitet: Pamela am 1 Nov. 2012
I tried this code. Can you correct it for me and how can i use this axes and PCA to study the asymmetry of the object.
xfact = s.MajorAxisLength./2*cos(s.Orientation*pi/180);
yfact = s.MajorAxisLength./2*sin(s.Orientation*pi/180);
Major = line(xfact+s.Centroid(1),yfact+s.Centroid(2));
Image Analyst
Image Analyst am 2 Sep. 2012
Pamela, I can't run your code because I don't have your image or your segmentation function. But common reasons for things being reversed are getting (row, column) confused with (x,y) when it should correspond to (y, x), and/or plotting points on a different axes than the image, where the YDir property is going the opposite way. Recall that the standard for images is for the top line to be 1 and higher line numbers are below that. This is opposite to the convention that you have is you just use plot() to plot some numbers in a brand new axes. However, plot will be correct if you used "hold on" and plotted in the same axes right over the top of your image.
Pamela
Pamela am 3 Sep. 2012
Bearbeitet: Pamela am 1 Nov. 2012
Thank you, It works now. I managed to draw the two axes but now I need to study the asymmetry of the region. Can you tell me how can I use these axes and the PCA to study the asymmetry of the ROI.
Can you do something along these lines:
positivePC1Elements = PC1_image >= 0;
negativePC1Elements = PC1_image < 0;
meanPositivePC1 = mean(PC1_image(positivePC1Elements));
meanNegativePC1 = mean(PC1_image(negativePC1Elements));
if abs(meanPositivePC1 - meanNegativePC1) < someTolerance
% They're close
else
% They're different
end
Pamela
Pamela am 3 Sep. 2012
Thank you Image Analyst, Can you explain to me more because I have no idea about PCA. What represents the variables used??
Pamela
Pamela am 7 Sep. 2012
Bonjour Et comment faire pour ajouter 2 axes de plus et pour pouvoir diviser la région en 8 parties en utilisant 4 axes en total??? Je compte sur votre aide pour pouvoir avancer
Image Analyst
Image Analyst am 7 Sep. 2012
I can't really give you a course in PCA here. Basically they are the major directions of your independent variables, which can be combinations of your actual variables.
Pamela
Pamela am 9 Sep. 2012
Bearbeitet: Pamela am 9 Sep. 2012
Hi! To study the similarity between 2 images we should use these steps???
-Calculate the mean of the input images
-Subtract the mean from the input images to obtain the mean-shifted images
-Calculate the eigenvectors and eigenvalues of the mean-shifted images
-Order the eigenvectors by their corresponding eigenvalues, in decreasing order
-Retain only the eigenvectors with the largest eigenvalues (the principal components)
-Project the mean-shifted images into the eigenspace using the retained eigenvectors
-Calculate the Euclidean distance
It's the same solution to study the asymmetry of the region?? Can this help me??
Thanks
Image Analyst
Image Analyst am 9 Sep. 2012
Pamela, I haven't heard of that method to determine similarity. Much more common is SSIM ( http://en.wikipedia.org/wiki/SSIM) and friends, or even PSNR. Or you can use image moments: http://en.wikipedia.org/wiki/Image_moment

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by