Login  Register

Re: Ideas for Algorithm

Posted by David Webster on Jul 30, 2011; 5:36am
URL: http://imagej.273.s1.nabble.com/Ideas-for-Algorithm-tp3683675p3683676.html

jason,

I thgink you can what you want using existing ImageJ menu function and a
macro without doing any pixel crunching algorithm development yourself.

You may/will need to furthur preprocess your image by using
Process/Binary/Make Binary and Process/Binary/Fill Holes. This converts the
stamps to a bunch of solid white rectangular objects (or Particles).

Then, do Analyze/Set Measurements and select Area, Bounding Box. and I think
Shape Descriptors (this will get aspect ratio).

Now run Analyze/Analyze Particles. You will get the selected properties
including the Bounding Box spec in a Results Table. You may want to write
some macro code to eliminate objects that are to small (area) or to "skinny"
(aspect ratio). This can be done using built in macro functions to get
Column/row data from the table and to delete rows as needed.


David Webster

On Fri, Jul 29, 2011 at 3:14 PM, Jason Drake <[hidden email]> wrote:

> Hi .... I am writing (or rather have substantially written) a program in
> Java to take a scanned page of stamps and attempt to create subimages of
> the
> stamps (and allow me to quickly save them in certain directories with
> particular names).
>
> I am struggling a little bit to come up with the right algorithm to "box
> off" the stamp images that I need to crop.  I just need the rectangular
> bounding boxes so I can present these in my interface, make any changes and
> proceed in the application to burst them into subimages.
>
> An example image is here (warning it is a 50Mb image):
> http://stamps.drakeserver.com/scan005.jpg
>
> Though investigation I found ImageJ.  One thing I have managed to use
> ImageJ
> for is to convert the image to binary format (and filter with a threshold).
> This gives me a working image (obviously my cropping will occur from the
> original) that is easier to deal with.  I may also use their image object
> instead of BufferedImages as these are memory hogs:
>
> Here is the filtered image: http://stamps.drakeserver.com/scan005-5.jpg
>
> My current algorthim is quite dum.... I start in the top left and proceed
> on
> a forty-five degree angle toward the bottom right.  As soon as a catch a
> color change I mark it and attempt to achieve a 10 pixel threshold.  At
> this
> occurance, I will try and find the top left corner of a stamp, and
> conversely attempt to find the lower right corner. Since they are in rows,
> I
> will move to the right and attempt the same thing for stamps to the right
> (if I hit the edge I go to next row).  I keep track of the lowest "y" value
> and use that for my next row.  The perforations make this tricky.  The
> algorithm is only ~ 80% efficient and struggles when I come into gaps (ie.
> stamps I have removed) I also can skip rows if there are not stamps in the
> first couple slots on the left.....
>
> Another thought I had was to start top right and simply scan to the right.
> As soon as I hit multiple "white" pixels (say 10) I start to determine if
> there is an area under them (ie. it isn't simply a reflection line but
> represents a stamp shape). I proceed down the rows until I hit matches.
>
> My background is engineering and computer science (but not graphics
> focussed) so I am not particularly up-to-speed with algorithms for this
> type
> of thing.  I would welcome any input on how to computationally solve this.
> It will drastically save me time in scannign and cataloguing my collection
> (although I have to admit the time I have put into my program could've
> better been used on my hobby and just use Gimp, but well..... the computer
> scientist in me loves to tinker.
>
> -Jason
>