# Image/Pattern Recognition

**URL:** <https://rubytalk.org/t/image-pattern-recognition/52029>\
**Category:** ruby-talk\
**Created:** [27 February 2009 14:56 UTC](https://rubytalk.org/t/image-pattern-recognition/52029 "2009-02-27T14:56:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Becky\_Franklin](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@Becky\_Franklin](https://rubytalk.org/u/Becky_Franklin)\
**Post date:** [27 February 2009 14:56 UTC](https://rubytalk.org/t/image-pattern-recognition/52029/1 "2009-02-27T14:56:14Z")

</div>

Hey folks,

I have a project I'm trying to work out the feasibility of being able to  
do - I want to process images that consist of a grid of squares  
containing symbols, and I want to be able to break down the grid so that  
the program can work out how many of each symbol there are and where it  
is on the grid. Not sure if this is something that's going to be do-able  
from what I've googled! Does RMagick or any of the gems have a possible  
solution to this?

Hope that makes some sense!  
Becky

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Serabe](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@Serabe](https://rubytalk.org/u/Serabe)\
**Post date:** [27 February 2009 15:07 UTC](https://rubytalk.org/t/image-pattern-recognition/52029/2 "2009-02-27T15:07:35Z")

</div>

You can use get\_pixels (  
[http://www.imagemagick.org/RMagick/doc/image2.html#get\_pixels](http://www.imagemagick.org/RMagick/doc/image2.html#get_pixels) ) for  
getting pixels in a region and store\_pixels for (yes, you guessed it)  
store pixels in a image.

Regards,

Serabe

> **···**
>
> 2009/2/27 Becky Franklin \<bex\_3000@hotmail.com\>:
> 
> > Hey folks,
> > 
> > I have a project I'm trying to work out the feasibility of being able to  
> > do - I want to process images that consist of a grid of squares  
> > containing symbols, and I want to be able to break down the grid so that  
> > the program can work out how many of each symbol there are and where it  
> > is on the grid. Not sure if this is something that's going to be do-able  
> > from what I've googled! Does RMagick or any of the gems have a possible  
> > solution to this?
> 
> --  
> [http://www.serabe.com](http://www.serabe.com)

---

<div class="post-metadata">

**Author:** ![Chris6](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@Chris6](https://rubytalk.org/u/Chris6)\
**Post date:** [27 February 2009 15:44 UTC](https://rubytalk.org/t/image-pattern-recognition/52029/3 "2009-02-27T15:44:06Z")

</div>

Haven't used it but the camellia Image processing library looks like  
it might be useful  
[http://camellia.sourceforge.net/index.html](http://camellia.sourceforge.net/index.html)

Cheers  
Chris

> **···**
>
> On Feb 27, 9:56 am, Becky Franklin \<bex\_3...@hotmail.com\> wrote:
> 
> > Hey folks,
> > 
> > I have a project I'm trying to work out the feasibility of being able to  
> > do - I want to process images that consist of a grid of squares  
> > containing symbols, and I want to be able to break down the grid so that  
> > the program can work out how many of each symbol there are and where it  
> > is on the grid. Not sure if this is something that's going to be do-able  
> > from what I've googled! Does RMagick or any of the gems have a possible  
> > solution to this?
> > 
> > Hope that makes some sense!  
> > Becky  
> > --  
> > Posted viahttp://www.ruby-forum.com/.

---

<div class="post-metadata">

**Author:** ![Becky\_Franklin](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@Becky\_Franklin](https://rubytalk.org/u/Becky_Franklin)\
**Post date:** [27 February 2009 15:14 UTC](https://rubytalk.org/t/image-pattern-recognition/52029/4 "2009-02-27T15:14:40Z")

</div>

Serabe wrote:

> **···**
>
> > 2009/2/27 Becky Franklin \<bex\_3000@hotmail.com\>:
> > 
> > > Hey folks,
> > > 
> > > I have a project I'm trying to work out the feasibility of being able to  
> > > do - I want to process images that consist of a grid of squares  
> > > containing symbols, and I want to be able to break down the grid so that  
> > > the program can work out how many of each symbol there are and where it  
> > > is on the grid. Not sure if this is something that's going to be do-able  
> > > from what I've googled! Does RMagick or any of the gems have a possible  
> > > solution to this?
> > 
> > You can use get\_pixels (  
> > [http://www.imagemagick.org/RMagick/doc/image2.html#get\_pixels](http://www.imagemagick.org/RMagick/doc/image2.html#get_pixels) ) for  
> > getting pixels in a region and store\_pixels for (yes, you guessed it)  
> > store pixels in a image.
> > 
> > Regards,
> > 
> > Serabe
> 
> Wow that's pretty simple! Gotta love Ruby :o) Thanks so much for the  
> quick response :o)  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [27 February 2009 15:19 UTC](https://rubytalk.org/t/image-pattern-recognition/52029/5 "2009-02-27T15:19:11Z")

</div>

Serabe wrote:

> Becky Franklin:

> > I have a project I'm trying to work out the feasibility of being able to  
> > do - I want to process images that consist of a grid of squares  
> > containing symbols, and I want to be able to break down the grid so that  
> > the program can work out how many of each symbol there are and where it  
> > is on the grid. Not sure if this is something that's going to be do-able  
> > from what I've googled! Does RMagick or any of the gems have a possible  
> > solution to this?
> 
> You can use get\_pixels (  
> [http://www.imagemagick.org/RMagick/doc/image2.html#get\_pixels](http://www.imagemagick.org/RMagick/doc/image2.html#get_pixels) ) for  
> getting pixels in a region and store\_pixels for (yes, you guessed it)  
> store pixels in a image.

That is as far from pattern recognition as atoms are from elephants!

Becky needs to google for "chain code". I really doubt a Ruby implementation is available, because the algorithms to do it in less than polynomial time are secret.

> **···**
>
> --  
> &nbsp;&nbsp;&nbsp;Phlip

---

<div class="post-metadata">

**Author:** ![Serabe](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@Serabe](https://rubytalk.org/u/Serabe)\
**Post date:** [27 February 2009 15:24 UTC](https://rubytalk.org/t/image-pattern-recognition/52029/6 "2009-02-27T15:24:44Z")

</div>

BTW, you can use import\_pixels and export\_pixels too.

Regards,

Serabe

> **···**
>
> --
> 
> > **[Conecto ergo sum.](http://www.serabe.com)**
> >
> > Non conecto ergo urgueo.

---

<div class="post-metadata">

**Author:** ![Serabe](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@Serabe](https://rubytalk.org/u/Serabe)\
**Post date:** [27 February 2009 15:48 UTC](https://rubytalk.org/t/image-pattern-recognition/52029/7 "2009-02-27T15:48:24Z")

</div>

Becky said that images consist of a grid of squares. I just pointed  
him that RMagick has some methods for retrieve and store pixels. I  
know it is not pattern recognition, but at least, he is one step  
closer now.

Regards,

Serabe

> **···**
>
> 2009/2/27 Phlip \<phlip2005@gmail.com\>:
> 
> > That is as far from pattern recognition as atoms are from elephants!
> 
> --  
> [http://www.serabe.com](http://www.serabe.com)

---

<div class="post-metadata">

**Author:** ![Becky\_Franklin](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@Becky\_Franklin](https://rubytalk.org/u/Becky_Franklin)\
**Post date:** [27 February 2009 16:00 UTC](https://rubytalk.org/t/image-pattern-recognition/52029/8 "2009-02-27T16:00:14Z")

</div>

Thanks so much for the responses folks they've been so helpful!

I think with a load of maths I can iterate through each of the squares  
in the grid as it will only be black and white - unless Camellia or  
RMagick have any sort of compare pixels functionality?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Becky\_Franklin](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@Becky\_Franklin](https://rubytalk.org/u/Becky_Franklin)\
**Post date:** [27 February 2009 16:07 UTC](https://rubytalk.org/t/image-pattern-recognition/52029/9 "2009-02-27T16:07:31Z")

</div>

Becky Franklin wrote:

> Thanks so much for the responses folks they've been so helpful!
> 
> I think with a load of maths I can iterate through each of the squares  
> in the grid as it will only be black and white - unless Camellia or  
> RMagick have any sort of compare pixels functionality?

Looks like find\_similar\_region might be what I'm looking for - love this  
language!

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Serabe](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@Serabe](https://rubytalk.org/u/Serabe)\
**Post date:** [27 February 2009 16:08 UTC](https://rubytalk.org/t/image-pattern-recognition/52029/10 "2009-02-27T16:08:46Z")

</div>

Here:

[http://www.imagemagick.org/RMagick/doc/struct.html#Pixel](http://www.imagemagick.org/RMagick/doc/struct.html#Pixel)

Take a look at \<=\> and fcmp methods.

Regards,

Serabe

> **···**
>
> 2009/2/27 Becky Franklin \<bex\_3000@hotmail.com\>:
> 
> > Thanks so much for the responses folks they've been so helpful!
> > 
> > I think with a load of maths I can iterate through each of the squares  
> > in the grid as it will only be black and white - unless Camellia or  
> > RMagick have any sort of compare pixels functionality?
> 
> --  
> [http://www.serabe.com](http://www.serabe.com)
