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