the edges in digital image can be detected by dividing the image into blocks and fined the contrast of each block, so the blocks of high contrast contains edges and not flat and the others of low variance are flat.
You can use edge detection filters to detect any patch you are working have edges. Then binarize edge image and count pixels on edges. Flat region should give lower edge count value. Finally, with a threshold value you can decide your patch is homogeneous (flat) region or heterogeneous.