Fast way to do a block-wise threshold operation


Giving an image in gray supposed to be 320*240, and I want to do a block-wise (square block) threshold to get binary image of each block. It seems to be a mask operation using each pixel as the center of the block. I can do it by taking each block out from the original image and then do a threshold. This is done pixel by pixel and pixels next to image borders are not involved. I mean pixels on borders or fall into border regions that are smaller than half width of the block are ignored. Is there a way to do it less time-consuming. Thanks.

please tell us, – what do you try to achieve with it ? why " block-wise threshold " ?
are you looking for adaptiveThreshold ? (which is done on blocks already) ?

This is done pixel by pixel

oh, noes, not the way to do it in a highly vectorized library like this …

OK. Suppose I have a filter. I want the filter move pixel by pixel throughout the image to find out which part (it is the block here) can give it the max response. I try using a binary threshold first as a test.

Telling in an other way. Starting with a pixel next to the left top corner, from where I can get a single block. Do a threshold to it getting its binary. Move to the one right next to this pixel and do the same thing till I do it for all image.