From blobs to lines

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
LeyreM

From blobs to lines

Post by LeyreM »

Hi, I would like to simplify an image transforming some areas to just simple lines, I mean, obtaining just one line from a one-color blob. I've tried using morphological operations so the blob was reduced several times, but the result is not too clear, it's like some little blobs that makes the sense of making the shape of a line, but it's not a real line.
Does anybody know how I could get this? Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: From blobs to lines

Post by fmw42 »

By "line", do you mean a row of the image or do you mean some linear feature in the image?
LeyreM

Re: From blobs to lines

Post by LeyreM »

The objective would be to erase everything but the most important pixels of the blobs (the ones that stablish the shape or curvature of the blob), so I could use their coordinates to create a line or an arc, depending on the caracteristics of each blob.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: From blobs to lines

Post by fmw42 »

I think you will need to post a link to an example image and describe what you want to extract.
LeyreM

Re: From blobs to lines

Post by LeyreM »

This is a example of what I would like to extract...

http://s875.photobucket.com/albums/ab31 ... g&newest=1

Then, I would like to obtain only a line from the the several white blobs on the black part of the image (the isolated white blob shouldn't exist).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: From blobs to lines

Post by fmw42 »

floodfill the outer white area with black, then threshold to black/white. see http://www.imagemagick.org/Usage/draw/#color

convert line.png -fuzz 70% -fill black -draw "color 0,0 floodfill" -alpha off -threshold 50% line_flood.png
LeyreM

Re: From blobs to lines

Post by LeyreM »

Thanks, it worked... but it wasn't was I was really looking for.

Even if the line seems quite clear in the image it's not a real line but an amount of blobs. I would like to have just a line (one pixel in each row, connected with the upper and lower-row pixels). I want to make something like an erode but the results are not the best, in fact I would like something like "Thinning down to a Skeleton", but in my version the morphology doesn't exist. Any idea of how solving this?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: From blobs to lines

Post by fmw42 »

upgrade your IM so that you can use thinning in -morphology. That is all I can suggest. There are no other thinning type functions in IM. The best you can do is print out all the white pixels and do your own processing external to IM and fit a (straight?) line to the points. Perhaps Anthony who wrote the morphology function may have other ideas.


convert line_flood.png txt:- | grep "white" | sed -n 's/^\(.*,.*\):.*$/\1/p'
Last edited by fmw42 on 2010-08-25T19:22:35-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: From blobs to lines

Post by fmw42 »

FYI: If I use -morphology to close up some gaps and then thin on the processed image from above, this is what I get:

Your input:
http://www.fmwconcepts.com/misc_tests/line.png


convert line.png -fuzz 70% -fill black -draw "color 0,0 floodfill" -alpha off -threshold 50% line_flood.png

http://www.fmwconcepts.com/misc_tests/line_flood.png


convert line_flood.png -morphology close square -morphology Thinning:-1 Skeleton line_flood_close_thin.png

http://www.fmwconcepts.com/misc_tests/l ... e_thin.png
LeyreM

Re: From blobs to lines

Post by LeyreM »

Thanks for the help, I downloaded the last ImageMagick version so I could use morphology, and I got exactly what I wanted with the comands written by fmw42
Post Reply