I need to implement a locally adaptive threshold algorithm on a grayscale image in matlab. I use a sliding window over the image and calculate the threshold for the block using Otsu's method, which works well for blocks with non-uniform intensities.
However, when I apply this method to blocks with uniform intensities, I get very busy (junk) blocks. I want to set these blocks to either black or white in the result. I can decide whether to use black and white by comparing the global threshold value to the mean of the block (is this a good approach?).
My main question is: how to decide whether a block is uniform or not, or rather, how do I know which blocks to threshold and which to completely set to black or white?