How to divide image into X*Y blocks and count number of pixels for each block?

1 view (last 30 days)
Hi,
I have 4096*3000 rgb image. i want to divide that image into X*Y blocks. I would like to calculate number of pixels in every block. At the end i need to have X*Y matrix, such that every elements in that matrix represents the number of pixels in respective block. How i can do that?
Thanks in advance.
  1 Comment
Guillaume
Guillaume on 14 Mar 2018
Isn't the numbers of pixels in an X pixels * Y pixels block equal to X*Y ?
Perhaps you are asking for the number of pixels that have a given property (e.g. are white) but nowhere have you mentioned that in your question.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 14 Mar 2018
Edited: Image Analyst on 14 Mar 2018
Try this:
[rows, columns, numberOfColorChannels] = size(rgbImage);
rowsPerBlock = round(rows / Y)
colsPerBlock = round(columns / X)
pixelsPerBlock = rowsPerBlock * colsPerBlock
Also see demos for blockproc(), attached.

Community Treasure Hunt

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

Start Hunting!