Is there a way to filter out lines that are within a common color?

I have a raster image with lines marking lake depths. I was wondering if there is a good way to eliminate these lines. The color on either side of the lines is the same exact value, but the lines are various shades of black/grey.

example.xcf (205.6 KB)

I’m hoping to end up with the outlines of the common lake depth colors (at most there will be 3 shades of blue) so I can then CNC these to 3 different physical depths.

example

If the lines are not too close to each other you can use a median blur:

Otherwise, in places like the vicinity of the 2.5 mark at the bottom there is no blue…

@eradicatore

Bonjour,
A quick test on your image with G’MIC GIMP QT
This is simply an example and there is surely better.
resultat_test_lignes

Code:

to_rgba
+replace_color 30%,0,100,100,100,255,0,0,0,0
replace_color. 10%,0,124,147,172,255,0,0,0,0
replace_color. 5%,0,136,169,203,255,0,0,0,0
dilate_circ.. 20
erode_circ.. 20
blend alpha
dilate_circ 2
erode_circ 2
2 Likes

Bonjour!

Wow, that looks perfect! I was thinking of learning pythonfu for gimp, but this already looks perfect. I’ll see if I can reproduce your instructions. And then I’ll try expanding to delete the numbers which may work very similarly.

@eradicatore

To find more about G’MIC commands which can also be used in the GIMP plug-in there is PDF documentation:
G’MIC The Handbook

replace_color page 462
dilate_circ page 168
erode_circ page 205
blend pages 85/86

:o)

1 Like

Thank you so much!

This is actually PERFECT! I am on a Mac, so I used homebrew to install gmic CLI. And this pdf you shared explains things like the + prepending (page 6) and gives examples of the tools as CLI examples. (I was starting to look at Basics)

(Need to figure out the . and … you have in a few lines)

From Page 6 or so:

"Command selections [-1], [-2] and [-3] are so often used they have their own shortcuts,respectively ., … and … For instance, command blur… is equivalent to blur[-2].These shortcuts work also when specifying command arguments.

@eradicatore

Code:

to_rgba # image in mode RGBA
+replace_color 30%,0,100,100,100,255,0,0,0,0 # image origine and + = new image with replace color
# 2 images : [-2] or .. = image RGBA / [-1] or . = image with replace color
replace_color. 10%,0,124,147,172,255,0,0,0,0 # image [-1] or . with new replace color
replace_color. 5%,0,136,169,203,255,0,0,0,0 # image [-1] or . with new replace color
dilate_circ.. 20 # dilate image [-2] or ..
erode_circ.. 20 # erode image [-2] or ..
blend alpha # blend the 2 images
dilate_circ 2 # dilate image
erode_circ 2 # erode image

Thanks @gstalnaker for the info about the list, and @samj for comments on the code. I got it to run at the CLI by just adding each line to the one CLI command. I’m assuming there is probably a way to put the code into a file and use the file as the commands for the CLI though. I’ll keep reading.

Again, love the output. It worked very well for this overall question I had! And love learning about a new image processing tool like G’mic! Added to the tool chest for sure.

@eradicatore

Bonjour,
Here are a few command lines for G’MIC.
The files are in the ‘test_eradicatore.zip’ archive (at the end of this message).

To update G’MIC CLI

gmic update

To see the image

gmic i example.png

To see the effect of the filter on the image

gmic m a.gmic i example.png eradicatore_eliminate_lines

To see the original image and the effect of the filter

gmic m a.gmic i example.png +eradicatore_eliminate_lines

To export the result in PNG

gmic m a.gmic i example.png eradicatore_eliminate_lines o without_lines.png

To add options and export the result to PNG

gmic m a.gmic i example.png eradicatore_eliminate_lines pow 1.3 cut 0,255 o without_lines_pow.png

To see the original image, the effect and the options

gmic m a.gmic i example.png +eradicatore_eliminate_lines +pow. 1.3 cut. 0,255

file ‘a.gmic’


eradicatore_eliminate_lines : # The name of the filter
to_rgba # image in mode RGBA
+replace_color 30%,0,100,100,100,255,0,0,0,0 # image origine and + = new image with replace color
# 2 images : [-2] or .. = image RGBA / [-1] or . = image with replace color
replace_color. 10%,0,124,147,172,255,0,0,0,0 # image [-1] or . with new replace color
replace_color. 5%,0,136,169,203,255,0,0,0,0 # image [-1] or . with new replace color
dilate_circ.. 20 # dilate image [-2] or ..
erode_circ.. 20 # erode image [-2] or ..
blend alpha # blend the 2 images
dilate_circ 2 # dilate image
erode_circ 2 # erode image


test_eradicatore.zip (204.7 KB)

1 Like

Ah, nice. So if you add code to a module file, and bundle it as a filter with a (funcition/procedure) name line, then you can use it. This is great! Thanks again!

@eradicatore

…to delete the numbers…

From the initial code it is possible to add this line:

replace_color. 20%,0,22,0,245,255,0,0,0,0

to obtain this code:

to_rgba
+replace_color 30%,0,100,100,100,255,0,0,0,0
replace_color. 10%,0,124,147,172,255,0,0,0,0
replace_color. 5%,0,136,169,203,255,0,0,0,0
replace_color. 20%,0,22,0,245,255,0,0,0,0
dilate_circ.. 20
erode_circ.. 20
blend alpha
dilate_circ 2
erode_circ 2

example_test2

It is always possible to obtain a better result, for example, by adding others ‘replace_color’ at the end of the code.

1 Like

@eradicatore

This is the best I can do using only color replacements.

example_test3

A new code :

to_rgba
+dilate_circ 30
erode_circ. 30
replace_color. 10%,0,152,197,242,255,0,0,0,0
replace_color. 90%,0,255,255,255,255,114,182,239,255
replace_color. 0,0,0,0,0,0,152,197,242,255
replace_color.. 30%,0,92,95,98,255,0,0,0,0
replace_color.. 10%,0,133,164,196,255,0,0,0,0
replace_color.. 10%,0,120,143,166,255,0,0,0,0
replace_color.. 60%,0,22,0,245,255,0,0,0,0
rv
blend alpha
dilate_circ 2
erode_circ 2

:o)

3 Likes

Wow! That’s (again) amazing. Thanks so much for sharing that and this whole thread introduction to gmic. This will be perfect for my CNC project to cut each of these colors to a depth and paint them. I was going to laser etch the roads.

These codes are not perfect.
There will surely be corrections to be made before using the CNC, for example with the last code:

example_test3_corrections

I added a filter ‘Topographie …’ in G’MIC GIMP QT which partially processs the original image and some rendering of the site https://www.gpsnauticalcharts.com/


test :
Test_samj_Topographie_Eliminate_Contour_Lines.xcf.bz2 (965.7 KB)