graphicsmagick

How to get print of coordinates for Connected components labeling in GraphicsMagick?


Is there a way to scan the image pixel by pixel and print the coordinates of each pixel regions by color? similiar to this ImageMagick´s feature Uniquely Label Connected Regions. I'd like to do it in bash or python to identify the coordinates of several rectangles inside an image, each rectangle is of different color or has a border line of some color. I asked this in superuser before. here

Example how this can be done in ImageMagick.

magick objects.gif -connected-components 4 -auto-level -depth 8 objects.png

Objects (id: bounding-box centroid area mean-color):
  0: 256x171+0+0 119.2,80.8 33117 srgb(0,0,0)
  2: 120x135+104+18 159.5,106.5 8690 srgb(255,255,255)
  3: 50x36+129+44 154.2,63.4 1529 srgb(0,0,0)
  4: 21x23+0+45 8.8,55.9 409 srgb(255,255,255)
  1: 4x10+252+0 253.9,4.1 31 srgb(255,255,255)

UPDATE

Consider this input image.

enter image description here

I have a kind of large IM script in bash that detects dynamically the coordinates of the rectangles with charts and the small rectangles at the top (blue, red, green, purple). First converts to black and white the input image and prints the coordinates. Then I use the output of this script to crop all the rectangles for a further processing. The thing is takes some time to make all the processes and for what I found recently, graphicsmagick claims to be faster.

convert 'input.png' \
         -transparent "#FFFFFF" \
         -transparent "#27A9E3" \
         -transparent "#28B779" \
         -transparent "#E7191B" \
         -transparent "#852B99" \
         -alpha extract -negate \
         -define connected-components:verbose=true \
         -define connected-components:mean-color=true \
         -define connected-components:area-threshold=5000 \
         -connected-components 8 black_and_white.png

Solution

  • Three ways to work out GraphicsMagick doesn't provide "Connected Components" processing...

    1. See my answer What's the Difference between GraphicsMagick and ImageMagick?

    1. Look at the online manual, here, search for the word "connected" and discover it isn't there.

    1. Download and unpack the latest source code from September 2023 and search all the files for the word "connected" and come up empty:

      find GraphicsMagick-1.3.42 -type f -exec grep -i connected {} \;