Find Image components using python/PIL
<p>Is there a function in PIL/Pillow that for a grayscale image, will separate the image into sub images containing the components that make up the original image? For example, a png grayscale image with a set of blocks in them. Here, the images types always have high contrast to the background.</p>

<p>I don't want to use openCV, I just need some general blob detection, and was hoping Pillow/PIL might have something that does that already.</p>

<p>Not using PIL, but worth a look I think:
I start with a list of image files that I've imported as a list of <code>numpy</code> arrays, and I create a list of boolean versions where the <code>threshold</code> is <code>&gt; 0</code></p>

<pre><code>from skimage.measure import label, regionprops
import numpy as np

bool_array_list= []

for image in image_files:
    bool_array = np.copy(image)
    bool_array[np.where(bool_array &gt; 0)] = 1
    bool_array_list.append(bool_array)

img_region_list = []
</code></pre>

<p>Then I use label to identify the different areas, using 8-directional connectivity, and <code>regionprops</code> gives me a bunch of metrics, such as size and location.</p>

<pre><code>for item in bool_array_list:
    tmp_region_list = regionprops(label(item, 
                                        connectivity=2
                                       )
                                 )
    img_region_list.append(tmp_region_list)
</code></pre>

python pillow