How a binary image can be divided into four equal parts using loop ?
Show older comments
I have a binary image . I want to divide this into 4 equal parts using a loop and want to store each part individually. later I want to find out the no of white pixels in each parts.
3 Comments
Image Analyst
on 23 Feb 2018
How is the splitting going to be done? Along and perpendicular to the major axis with the 4 corner point at the centroid of the blob? Just splitting into 4 equal quadrants regardless of where where your binary blobs lie? Can you post your image and show where you want to do the splitting?
Zara Khan
on 24 Feb 2018
Image Analyst
on 25 Feb 2018
OK, but does this mean that the center of the quadrants will be located at the center of the blob, or at the center of the image? And I presume that edges parallel with the edges of the image are okay? And that it's okay if each quadrant does not have the same number of pixels in it?
Accepted Answer
More Answers (2)
I'm not sure why or even how you'd use a loop.
[height, width, ncols] = size(yourimage);
splitimages = mat2cell(yourimage, [height height]/2, [width width]/2, ncols)
Your four images are splitimages{1}, splitimages{2}, splitimages{3}, and splitimages{4}.
To find the number of white pixels in each subimage:
numwhitepixels = cellfun(@(subimg) sum(sum(all(subimg == 1, 3))), splitimages); %assuming images of type double, where white == 1
edit: stupidly forgot the image argument to mat2cell!
sumaiya khan
on 7 Dec 2018
0 votes
How can I diagnolly divide the image into 4 quadrants using the centroid of the blob ?
Categories
Find more on Data Type Identification in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






