imagemagickmagickwand

How to colorize similar color regions like magic wand tool?


Please help on this. I´d like to isolate areas to find some coordinates based on colors to crop regions of interest later. Specifically, (1st) I want to colorize in black the similar gray regions and (2nd) the "1 pixel" height lines between, in order that black regions after the step 1 and 2 be connected like in output shown below.

When I analyse the image below with an image editor like Paint.net and select magic wand tool, locating it in position (x=395, y=190) with a tolerance of 32%, the similar gray regions are selected.Then I can manually colorize in black the selected area.

Magick Wand tool selecting similar grays with 32% of tolerance in Paint.net

enter image description here

I found the magicwand method in Fred´s scripts and try to send the example with logo2.png but says command not found, then I wasn´t able to try with my input image.

I'm running IM in cygwin under Windows.

$ convert -version
Version: ImageMagick 7.0.10-61 Q16 x86_64 2023-05-13 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): bzlib cairo djvu fftw fontconfig fpx freetype gslib gvc heic jbig jng jp2 jpeg lcms lqr lzma openexr pangocairo png ps raqm raw rsvg tiff webp x xml zlib



$ magicwand 160,200 -t 25 -f image -r inside -m edge -c red logo2.png logo2_out.png
-bash: magicwand: command not found

Original input image.

enter image description here

Expected output:

enter image description here


Solution

  • You can do that in Imagemagick with flood fill. (Alternate, use -fuzz XX% -fill black -opaque "rgb(XX,XX,XX)" for the gray XX value you want for middle gray in the image). Pick a coordinate at the mid gray color (not too dark gray and not too light gray). Adjust the fuzz value as needed.

    Input:

    enter image description here

    magick picture2.png -alpha off -fuzz 12% -fill black -draw "color 340,125 floodfill" -alpha off x.png
    

    Result:

    enter image description here