Can anyone please explain the meaning of below code?
조회 수: 1 (최근 30일)
이전 댓글 표시
[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);
댓글 수: 0
채택된 답변
Walter Roberson
2017년 9월 10일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Modify Image Colors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!