[Numpy-discussion] [SciPy-User] Simple pattern recognition

Gökhan Sever gokhansever@gmail....
Mon Sep 21 14:14:27 CDT 2009


Ahh my blindness and apologies :)

The nice feeling of reinventing the wheel...

Probably I forgot to reshape the image data in the first place before
applying into ndimage.label().

However, this was a nice example to understand recursion, and get to know
some basics of computer vision and few libraries (OpenCV, pygraph) during my
research.

Thanks again for all kind replies.

On Mon, Sep 21, 2009 at 1:36 PM, David Warde-Farley <dwf@cs.toronto.edu>wrote:

> I think Zachary is right, ndimage does what you want:
>
> In [48]: image = array(
> [[0,0,0,1,1,0,0],
> [0,0,0,1,1,1,0],
> [0,0,0,1,0,0,0],
> [0,0,0,0,0,0,0],
> [0,1,0,0,0,0,0],
> [0,1,1,0,0,0,0],
> [0,0,0,0,1,1,0],
> [0,0,0,0,1,1,1]])
>
> In [57]: import scipy.ndimage as ndimage
>
> In [58]: labels, num_found = ndimage.label(image)
>
> In [59]: object_slices = ndimage.find_objects(labels)
>
> In [60]: image[object_slices[0]]
> Out[60]:
> array([[1, 1, 0],
>        [1, 1, 1],
>        [1, 0, 0]])
>
> In [61]: image[object_slices[1]]
> Out[61]:
> array([[1, 0],
>        [1, 1]])
>
> In [62]: image[object_slices[2]]
> Out[62]:
> array([[1, 1, 0],
>        [1, 1, 1]])
>
> David
>
> On 21-Sep-09, at 2:04 PM, Gökhan Sever wrote:
>
> > ndimage.label works differently than what I have done here.
> >
> > Later using find_objects you can get slices for row or column basis.
> > Not
> > possible to construct a dynamical structure to find objects that are
> > in the
> > in both axis.
> >
> > Could you look at the stackoverflow article once again and comment
> > back?
> >
> > Thanks.
> >
> > On Mon, Sep 21, 2009 at 12:57 PM, Zachary Pincus <
> zachary.pincus@yale.edu
> > >wrote:
> >
> >> I believe that pretty generic connected-component finding is already
> >> available with scipy.ndimage.label, as David suggested at the
> >> beginning of the thread...
> >>
> >> This function takes a binary array (e.g. zeros where the background
> >> is, non-zero where foreground is) and outputs an array where each
> >> connected component of non-background pixels has a unique non-zero
> >> "label" value.
> >>
> >> ndimage.find_objects will then give slices (e.g. bounding boxes) for
> >> each labeled object (or a subset of them as specified). There are
> >> also
> >> a ton of statistics you can calculate based on the labeled objects --
> >> look at the entire ndimage.measurements namespace.
> >>
> >> Zach
> >>
> >> On Sep 21, 2009, at 1:45 PM, Gökhan Sever wrote:
> >>
> >>> I asked this question at
> >> http://stackoverflow.com/questions/1449139/simple-object-recognition
> >>> and get lots of nice feedback, and finally I have managed to
> >>> implement what I wanted.
> >>>
> >>> What I was looking for is named "connected component labelling or
> >>> analysis" for my "connected component extraction"
> >>>
> >>> I have put the code (lab2.py) and the image (particles.png) under:
> >>> http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450/
> >>> labs
> >>>
> >>> What do you think of improving that code and adding into scipy's
> >>> ndimage library (like connected_components())  ?
> >>>
> >>> Comments and suggestions are welcome :)
> >>>
> >>>
> >>> On Wed, Sep 16, 2009 at 7:22 PM, Gökhan Sever
> >>> <gokhansever@gmail.com> 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.
> >>>
> >>> Thanks.
> >>>
> >>> --
> >>> Gökhan
> >>>
> >>>
> >>>
> >>> --
> >>> Gökhan
> >>> _______________________________________________
> >>> SciPy-User mailing list
> >>> SciPy-User@scipy.org
> >>> http://mail.scipy.org/mailman/listinfo/scipy-user
> >>
> >> _______________________________________________
> >> SciPy-User mailing list
> >> SciPy-User@scipy.org
> >> http://mail.scipy.org/mailman/listinfo/scipy-user
> >>
> >
> >
> >
> > --
> > Gökhan
> > _______________________________________________
> > SciPy-User mailing list
> > SciPy-User@scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090921/c9831aa6/attachment.html 


More information about the NumPy-Discussion mailing list