Clear Filters
Clear Filters

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

1 view (last 30 days)
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.

Answers (2)

KSSV
KSSV on 12 Dec 2018
A = nnz(binaryImage);
Or
A = sum(binaryImage(:));
  3 Comments
KSSV
KSSV on 12 Dec 2018
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),:);

Sign in to comment.


Image Analyst
Image Analyst on 12 Dec 2018
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!