Filter löschen
Filter löschen

Dividing a binary image into 8x8(64) blocks and storing no of black points in each block into an 8x8 matrix

2 Ansichten (letzte 30 Tage)
I want to divide a binary image into 8x8(64) blocks. Then I need to count the no. of black points in each block and stored them into an 8x8 matrix. My image has the size of 120x120. Please help me to do this.

Antworten (3)

Matt J
Matt J am 11 Jul. 2015
Bearbeitet: Matt J am 13 Jul. 2015
Using MAT2TILES ( Download ) from the File Exchange,
C=mat2tiles(yourImage,[8,8]);
counts = 64 - cellfun(@(c) nnz(c), C)

Image Analyst
Image Analyst am 11 Jul. 2015
Simply define a function to count zeros:
ZeroCounterFunction = @(theBlockStructure) sum(theBlockStructure.data(:) == 0);
Then call blockproc():
blockSize = [8 8];
blockyImage8 = blockproc(grayImage, blockSize, ZeroCounterFunction);
Attached is a full demo that will create this image:

Matt J
Matt J am 13 Jul. 2015
Bearbeitet: Matt J am 13 Jul. 2015
For large arrays, I suspect that the following, which uses SEPBLOCKFUN ( Dowload ) will be the fastest method, since it essentially requires only reshaping to get at the blocks,
counts = 64-sepblockfun(yourImage,[8,8],@sum)

Community Treasure Hunt

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

Start Hunting!

Translated by