[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: |
Wed, 04 Feb 2015 12:29:24 +0000 |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0 |
Follow-up Comment #6, bug #44100 (project octave):
Here is a new version for the 4 "ellipse" properties in the regionprops.m
file. (They are slightly improved with respect to the last version, now they
are more accurate for very small regions.)
case "majoraxislength"
if (N > 2)
warning ("regionprops: skipping majoraxislength for Nd image");
break
endif
for k = 1:num_labels
[Y, X] = find (L == k);
if (numel(Y) > 1)
% calculate (centralised) second moment of region
C = cov ([X(:), Y(:)], 1); % option 1 for normalisation with n
instead of n-1
C = C + 1/12.*eye(size(C,1)); % centralised second moment of 1
pixel is 1/12
lambda = eig (C);
retval (k).MajorAxisLength =4 * sqrt(max(lambda));
else
retval (k).MajorAxisLength = 1;
endif
endfor
case "minoraxislength"
if (N > 2)
warning ("regionprops: skipping minoraxislength for Nd image");
break
endif
for k = 1:num_labels
[Y, X] = find (L == k);
if (numel(Y) > 1)
% see case majoraxislength for explanations
C = cov ([X(:), Y(:)], 1);
C = C + 1/12.*eye(size(C,1));
lambda = eig (C);
retval (k).MinorAxisLength =4 * sqrt(min(lambda));
else
retval (k).MinorAxisLength = 1;
endif
endfor
case "eccentricity"
if (N > 2)
warning ("regionprops: skipping eccentricity for Nd image");
break
endif
for k = 1:num_labels
[Y, X] = find (L == k);
if (numel(Y) > 1)
% see case majoraxislength for explanations
C = cov ([X(:), Y(:)], 1);
C = C + 1/12.*eye(size(C,1));
lambda = eig (C);
major = 2 * sqrt(max(lambda));
minor = 2 * sqrt(min(lambda));
retval (k).Eccentricity = sqrt(1-(minor/major)^2);
else
retval (k).Eccentricity = 0; % a circle has 0 eccentricity
endif
endfor
case "orientation"
if (N > 2)
warning ("regionprops: skipping orientation for Nd image");
break
endif
for k = 1:num_labels
[Y, X] = find (L == k);
if (numel (Y) > 1)
% see case majoraxislength for explanations
C = cov ([X(:), Y(:)], 1);
C = C + 1/12.*eye(size(C,1));
[V, lambda] = eig (C);
[max_val, max_idx] = max (diag (lambda));
max_vec = V(:, max_idx);
retval (k).Orientation = -(180/pi) * atan (max_vec (2) / max_vec
(1));
else
retval (k).Orientation = 0;
endif
endfor
As you can see, I've also added the Orientation feature to my code. Those 4
properties are consistent now. And I think they should be Matlab compatible as
well. (It may be worth checking the results of the tests with a real Matlab
nevertheless. I don't have access to it for the next months.)
And here are a few tests for those 4 new features:
a = eye(4);
t = regionprops(a, 'majoraxislength');
assert(t.MajorAxisLength, 6.4291, 1e-3);
b = ones(5);
t = regionprops(b, 'majoraxislength');
assert(t.MajorAxisLength, 5.7735 , 1e-3);
c = [0 0 1; 0 1 1; 1 1 0];
t = regionprops(c, 'majoraxislength');
assert(t.MajorAxisLength, 4.1633 , 1e-3);
a = eye(4);
t = regionprops(a, 'minoraxislength');
assert(t.MinorAxisLength, 1.1547 , 1e-3);
b = ones(5);
t = regionprops(b, 'minoraxislength');
assert(t.MinorAxisLength, 5.7735 , 1e-3);
c = [0 0 1; 0 1 1; 1 1 0];
t = regionprops(c, 'minoraxislength');
assert(t.MinorAxisLength, 1.8037 , 1e-3);
a = eye(4);
t = regionprops(a, 'eccentricity');
assert(t.Eccentricity, 0.98374 , 1e-3);
b = ones(5);
t = regionprops(b, 'eccentricity');
assert(t.Eccentricity, 0 , 1e-3);
c = [0 0 1; 0 1 1; 1 1 0];
t = regionprops(c, 'eccentricity');
assert(t.Eccentricity, 0.90128 , 1e-3);
a = eye(4);
t = regionprops(a, 'orientation');
assert(t.Orientation, -45 , 1e-3);
b = ones(5);
t = regionprops(b, 'orientation');
assert(t.Orientation, 0 , 1e-3);
c = [0 0 1; 0 1 1; 1 1 0];
t = regionprops(c, 'orientation');
assert(t.Orientation, 45 , 1e-3);
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?44100>
_______________________________________________
Nachricht gesendet von/durch Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties,
H. G. <=
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties, H. G., 2015/02/25
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties, Carnë Draug, 2015/02/26
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties, H. G., 2015/02/27
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties, Carnë Draug, 2015/02/27
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties, Carnë Draug, 2015/02/27
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties, H. G., 2015/02/27
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties, Carnë Draug, 2015/02/27
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties, H. G., 2015/02/27
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties, Carnë Draug, 2015/02/27
- [Octave-bug-tracker] [bug #44100] image package: regionprops could easily deliver more properties, H. G., 2015/02/27