File size: 1,549 Bytes
d4035c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
function relativearea = LMlabeledarea(D, objectname)
%
% Returns the percentage of pixels labeled for each image.
%
n = length(D);
relativearea = zeros(n,1);
if nargin == 2
[D, j] = LMquery(D, 'object.name', objectname);
else
j = 1:n;
end
for i = 1:length(D);
relativearea(j(i)) = 0; % default value
if isfield(D(i).annotation, 'object')
Nobjects = length(D(i).annotation.object);
if Nobjects > 0
% Get image size
%if isfield(D(i).annotation, 'imagesize')
% ncols = D(i).annotation.imagesize.ncols;
% nrows = D(i).annotation.imagesize.nrows;
%else
ncols = 0; nrows = 0;
for n = 1:Nobjects
[X,Y] = getLMpolygon(D(i).annotation.object(n).polygon);
ncols = max(ncols, max(X));
nrows = max(nrows, max(Y));
end
%end
% Scaling (goes faster)
nrows = max(round(nrows/10),1);
ncols = max(round(ncols/10),1);
% Labeled pixels
mask = 0;
for n = 1:Nobjects
[X,Y] = getLMpolygon(D(i).annotation.object(n).polygon);
X = min(max(round(X/10),1),ncols);
Y = min(max(round(Y/10),1),nrows);
mask = mask + poly2mask(X,Y,nrows,ncols);
end
area = sum(mask(:)>0);
% Relative area
relativearea(j(i)) = area/(nrows*ncols);
end
end
end
|