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!
From blobs to lines
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: From blobs to lines
By "line", do you mean a row of the image or do you mean some linear feature in the image?
Re: From blobs to lines
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: From blobs to lines
I think you will need to post a link to an example image and describe what you want to extract.
Re: From blobs to lines
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).
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).
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: From blobs to lines
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
convert line.png -fuzz 70% -fill black -draw "color 0,0 floodfill" -alpha off -threshold 50% line_flood.png
Re: From blobs to lines
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?
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: From blobs to lines
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'
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: From blobs to lines
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
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
Re: From blobs to lines
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