[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #44100] image package: regionprops could easil
From: |
H. G. |
Subject: |
[Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties |
Date: |
Fri, 30 Jan 2015 23:38:55 +0000 |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0 |
Follow-up Comment #3, bug #44100 (project octave):
Yes, I think I can now confirm that the old (commented out) versions were NOT
Matlab compatible.
Here are my new proposals for the mentioned additional properties of
regionprops.m:
case "majoraxislength"
for k = 1:num_labels
[Y, X] = find (L == k);
Z0 = mean([Y, X],1); % calculate centroid position
x = X-Z0(:,2); % shifts coordinates to centroid position
y = Y-Z0(:,1);
if (numel(Y) > 1)
% calculate (centralised) second moment of region
C = cov ([x(:), y(:)]);
lambda = eig (C);
retval (k).MajorAxisLength =4 * sqrt(max(lambda));
else
retval (k).MajorAxisLength = 1;
endif
endfor
case "minoraxislength"
for k = 1:num_labels
[Y, X] = find (L == k);
Z0 = mean([Y, X],1); % calculate centroid position
x = X-Z0(:,2); % shifts coordinates to centroid position
y = Y-Z0(:,1);
if (numel(Y) > 1)
% calculate (centralised) second moment of region
C = cov ([x(:), y(:)]);
lambda = eig (C);
retval (k).MinorAxisLength =4 * sqrt(min(lambda));
else
retval (k).MinorAxisLength = 1;
endif
endfor
case "eccentricity"
for k = 1:num_labels
[Y, X] = find (L == k);
Z0 = mean([Y, X],1); % calculate centroid position
x = X-Z0(:,2); % shifts coordinates to centroid position
y = Y-Z0(:,1);
if (numel(Y) > 1)
% calculate (centralised) second moment of region
C = cov ([x(:), y(:)]);
lambda = eig (C);
major = 2 * sqrt(max(lambda));
minor = 2 * sqrt(min(lambda));
retval (k).Eccentricity = sqrt((major)^2 - (minor)^2) / major;
else
retval (k).Eccentricity = 0; % a circle has 0 eccentricity
endif
endfor
As said before, I could not 100% benchmark the results as compared to Matlab.
But I do get a very good match with the resulting image in this
Matlab-Tutorial:
http://blogs.mathworks.com/steve/2010/07/30/visualizing-regionprops-ellipse-measurements/
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?44100>
_______________________________________________
Nachricht gesendet von/durch Savannah
http://savannah.gnu.org/