DEV Community

Cover image for Create an RGBA histogram of a cat using Imagemagick
Christopher Konopka
Christopher Konopka

Posted on

Create an RGBA histogram of a cat using Imagemagick

How do I create a histogram of this cat image?

cat

Create a new bash script named create-histogram.sh.

# create-histogram.sh
#!/bin/bash
Enter fullscreen mode Exit fullscreen mode

Provide a ".png" file

echo "PNG please ~~~~~"
read PNG
Enter fullscreen mode Exit fullscreen mode

Remove ".png" from PNG

SPLICE=${PNG%????}
Enter fullscreen mode Exit fullscreen mode

Create the EXPORTFILE as ".txt"

EXPORTFILE="${SPLICE}.txt"
echo $EXPORTFILE
Enter fullscreen mode Exit fullscreen mode

Export a histogram ".txt" file based on the ".png"

convert $PNG -format %c histogram:info:- > $EXPORTFILE
Enter fullscreen mode Exit fullscreen mode

The exported histogram will look something like this ...

header

And a here is a clip of the workflow.

gif

Top comments (0)