Azzera filtri
Azzera filtri

Can anyone please explain the meaning of below code?

1 visualizzazione (ultimi 30 giorni)
[rows, columns] = size(grayImage);
circleCenterX = 120;
circleCenterY = 120; % square area 0f 500*500
circleRadius = 110; % big circle radius
circleImage = false(rows, columns);
[x, y] = meshgrid(1:columns, 1:rows);
circleImage((x - circleCenterX).^2 + (y - circleCenterY).^2 <= circleRadius.^2) = true;
b = and(circleImage,b);
labeledImage = bwlabel(b);
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
matrix = zeros(4,length(measurements));
vector = zeros(1,length(measurements));
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
matrix(:,k) = thisBB(:);
vector(k) = thisBB(2);
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','g','LineWidth',2 )
end
vector = sort(vector);

Risposta accettata

Walter Roberson
Walter Roberson il 10 Set 2017
The code creates a binary mask which is the inside of a circle of radius 110, centered at (120, 120). It then "ands" that mask with b, which has the effect of erasing everything in b that is outside the circle.
Components of the result are then labeled, and bounding boxes and area are found. The bounding boxes and area are recorded in the arrays "matrix" and "vector", and rectangles are plotted corresponding to each bounding box.
Finally, the areas are sorted -- but the original order is not kept track of, so it is not possible to associate the sorted areas with the corresponding bounding box. That final line
vector = sort(vector);
should be replaced by
[vector, sortorder] = sort(vector);
matrix = matrix(sortorder, :);
After that, the order of the bounding boxes would correspond to increasing area.

Più risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by