How can i calculate the area of white pixels in each quadrant and display it individually.

1 次查看(过去 30 天)
Using the centroid, a binary image is divided into four quadrants at an angle of 45 degree. I need to calculate the area of white pixels in each quadrant. How can i calculate the area of white pixels in each quadrant and display it individually.

回答(2 个)

KSSV
KSSV 2018-12-12
A = nnz(binaryImage);
Or
A = sum(binaryImage(:));
  3 个评论
KSSV
KSSV 2018-12-12
YOu can use imcrop four times for the parts you want. Or use:
I1=I(1:size(I,1)/2,1:size(I,2)/2,:);
I2=I(size(I,1)/2+1:size(I,1),1:size(I,2)/2,:);
I3=I(1:size(I,1)/2,size(I,2)/2+1:size(I,2),:);
I4=I(size(I,1)/2+1:size(I,1),size(I,2)/2+1:size(I,2),:);

请先登录,再进行评论。


Image Analyst
Image Analyst 2018-12-12
Construct triangles, like 3 or 4 points defining the vertices (2 along the edge and one at the center). Then use poly2mask(). Untested code follows:
[rows, columns, numColors] = size(binaryImage);
xCenter = columns/2;
yCenter = rows / 2;
x = [1, columns, xCenter, 1]; % Top triangle
y = [1, 1, yCenter, 1];
hold on;
plot(x, y);
mask = poly2mask(x, y, rows, columns);
pixelsInMask = binaryImage(mask); % a 1-2 vector of pixels in the triangle.
numWhitePixelsInMask = nnz(pixelsInMask);

Community Treasure Hunt

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

Start Hunting!

Translated by