I've got several images of characters from A-Z and 0-9 that have been generated with an artificial intelligence program and the problem is that all these characters don't have exactly the same hue because they've been generated one by one, one after the other. Do you know of a command-line program that could perform batch processing to standardize the hue of all the images at once, taking one of the images in the batch as the hue reference?

Add a comment
|
1 Answer
You can do the following:
- convert to HSL colourspace
- fix the first (Hue) channel to a constant value whilst retaining the existing Saturation and Lightness
- revert to RGB colourspace
Like this:
magick YOURIMAGE -colorspace hsl -channel R -evaluate set 40 -colorspace rgb result.png
Change 40 to other values for different hues. Set 160 for this colour.
If you have lots of files to do in the current directory, you can do them all in one go and write the resulting files into an output directory called OUTPUT like this:
mkdir OUTPUT
magick mogrify -path OUTPUT -colorspace hsl -channel R -evaluate set 40 -colorspace rgb *.png
If you want to overwrite, and discard your input files, and you are sure, omit the -path OUTPUT part from the command.
As regards determining the colour to use, you could do a reduction to 2 colours and print the colours out, discarding the whiter one like this:
magick letters.png -colors 2 result.png
magick letters.png -colors 2 -unique-colors txt:
# ImageMagick pixel enumeration: 2,1,255,srgba
0,0: (63,160,62,255) #3FA03EFF srgba(63,160,62,1)
1,0: (248,252,248,255) #F8FCF8FF srgba(248,252,248,1) <--- practically white


