[Numpy-discussion] Simple pattern recognition

Gökhan Sever gokhansever@gmail....
Thu Sep 17 10:14:30 CDT 2009

On Wed, Sep 16, 2009 at 8:43 PM, David Warde-Farley <dwf@cs.toronto.edu>wrote:

> On 16-Sep-09, at 8:22 PM, Gökhan Sever wrote:
> > Hello all,
> >
> > I want to be able to count predefined simple rectangle shapes on an
> > image as
> > shown like in this one:
> http://img7.imageshack.us/img7/2327/particles.png
> >
> > Which is in my case to count all the blue pixels (they are ice-snow
> > flake
> > shadows in reality) in one of the column.
> >
> > What is the way to automate this task, which library or technique
> > should I
> > study to tackle it.
> Hey Gokhan,

Hello David,

How are you?

> Well, scipy.ndimage.label() will be handy once you extract those
> columns one by one. Is one contiguous blue region considered one
> object? In that case, you'd be done.
That's true, the blue contiguous regions are the ones that I want to extract
from the image. See my new screenshot

GIMP's fuzzy selection tool (4th one from the top on the toolbox) selects
those areas (the background image on the ss) perfectly. I copied those
regions and put the on a new canvas using grayscale colorspace. The
foreground image zooms to the top portion of extracted regions. Using the
pen tool and the tiniest size I outlined the area that I am interested. We
were asked to measure the width and height of each similar ice particle
shadows (which are just the those contiguous extractions). For the sake of
simplicity we will just average the width and height to use a radius to
later calculate particle volumes. (Hah wondering how else would be possible
to calculate such irregular shaped particle volume if we weren't making this
assumption. (Any ideas?? -particle re-construction, edge smoothing, that
would be a topic for a master or phd thesis, I think)

So seems like what was done with the GIMP could be automated with the
approach you mentioned.

I use PIL to read my png file (after cropped the initial image to the column
of my interest) Like:

from PIL import Image
myim = Image('seccol.png)
imdata = np.array(myim.getdata())

>From this on, I am not sure what to provide to the structure parameter

label(input, structure=None, output=None)

I am correct on PIL usage or just a simple binary ready work, too?

> Once you've run label() you can use scipy.ndimage.find_objects() to
> get slices into the entire column that contain the contiguous region.
> If you want to try and count individual rectangles that may overlap,
> there are likely dynamic programming algorithms that can find the
> biggest rectangles. The truth is you can probably even do something
> pretty naive and then compile it with Cython and it'll go blazing fast.

Uhh this might be a little too complicated for this project. I don't think I
will need a Cython but depends can expand further.

> If you can be more specific about the kinds of "predefined simple
> rectangle shapes" we can probably tell you more.

Looking once again they are not predefined. I was thinking to loop through
each segment based on the smallest rectangle in the figure. The first
paragraph on this reply should clear my intention.

Thanks for your reply.

Hope your thesis work going well or successfully completed :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090917/db83ba3f/attachment-0001.html 

More information about the NumPy-Discussion mailing list