Borrar filtros
Borrar filtros

Can anyone please explain the meaning of below code?

1 visualización (últimos 30 días)
Manjiree Waikar
Manjiree Waikar el 10 de Sept. de 2017
Comentada: Manjiree Waikar el 11 de Sept. de 2017
[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);

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Sept. de 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.
  1 comentario
Manjiree Waikar
Manjiree Waikar el 11 de Sept. de 2017
Thank you so much sir. It helped me to understand very easily.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by