Removing small objects combining connected components and skeletonizing (possible bug with skeleton? 7.0.8)
Posted: 2019-07-17T01:51:16-07:00
Hi all,
I am usually able to solve problems using answers on this forum, but right now I am stuck, here is why.
I have several pictures looking like the following (which I actually drew in GIMP for this example):
My goal is to obtain an image that only contains the curve in the middle, removing the scale bar and other small objects. Like so:
My strategy is originally to use connected components with an area threshold that will remove all the small objects, but not the line. The difficulty is that because the scale bar is very thick in some images, it is hard to define an area threshold that will remove the scale bar in all images without removing the curve in others (using mogrify). My idea was to first skeletonize images, so that thickness problems will be out of the way, and the 'area' of the line will always be larger than that of any scale bar. Here is the code I am using now :
But Thinning appears to do strictly nothing. I have also tried on single pictures with :
Which also did not work. I use ImageMagick 7.0.8-53 Q16 x86_64 on Ubuntu 16.04.5 LTS Xenial (but I may also need to run the script on other computers). Is there a known bug with thinning in this version on IM? I have read bug report for previous versions, but it appeared that they should have solved since then.
On the original version of IM that was installed on this computer (which I think was 6.8 or 6.9, default for Ubuntu 16.04), Thinning did work, but I had to upgrade because connected components were not working, so I guess downgrading would not be the solution.
Any help with this is greatly appreciated, ideas of workaround are also welcome
Cheers
I am usually able to solve problems using answers on this forum, but right now I am stuck, here is why.
I have several pictures looking like the following (which I actually drew in GIMP for this example):
My goal is to obtain an image that only contains the curve in the middle, removing the scale bar and other small objects. Like so:
My strategy is originally to use connected components with an area threshold that will remove all the small objects, but not the line. The difficulty is that because the scale bar is very thick in some images, it is hard to define an area threshold that will remove the scale bar in all images without removing the curve in others (using mogrify). My idea was to first skeletonize images, so that thickness problems will be out of the way, and the 'area' of the line will always be larger than that of any scale bar. Here is the code I am using now :
Code: Select all
mogrify -threshold 50% *.png
mogrify -negate *.png
mogrify -morphology Thinning:-1 Skeleton *.png
mogrify -morphology Dilate Ring:2 *.png
mogrify \
-define connected-components:verbose=true \
-define connected-components:area-threshold=1800 \
-define connected-components:mean-color=true \
-connected-components 4 \
*.png
Code: Select all
convert example.png -morphology Thinning:-1 Skeleton result.png
magick example.png -morphology Thinning:-1 Skeleton result.png
magick convert example.png -morphology Thinning:-1 Skeleton result.png
On the original version of IM that was installed on this computer (which I think was 6.8 or 6.9, default for Ubuntu 16.04), Thinning did work, but I had to upgrade because connected components were not working, so I guess downgrading would not be the solution.
Any help with this is greatly appreciated, ideas of workaround are also welcome
Cheers