I use FFMPEG and Imagemagick to extract the color palette from an image or video with a Windows batch file,
:: get current folder name
for %%* in (.) do set CurrDirName=%%~nx*
:: get current filename
for /R %1 %%f in (.) do (
set CurrFileName=%%~nf
)
ffmpeg -i "%1" -vf palettegen "_%CurrFileName%_temp_palette.png"
convert "_%CurrFileName%_temp_palette.png" -filter point -resize 4200%% "_%CurrFileName%_palette.png"
del "_%CurrFileName%_temp_palette.png"
This outputs something like,
I need this to have better transition throughout the color blocks though, like all blues from darkest to lightest then transitioning to greens, yellows etc. like,
Is there a way/switch to create this with either Imagemagick/FFMPEG?
I don't like working on Windows, but I wanted to show you a technique you could use. I have therefore written it in
bash
but avoided nearly all Unix-y stuff and made it very simple. In order to run it on Windows, you would only need ImageMagick andawk
andsort
which you can get for Windows from here and here.I'll demonstrate using an image of random data that the script creates on around the third line:
Here is the script. It is pretty well commented and should convert easily enough to Windows if you like what it does.
If I set
NGROUPS
to 10, I get:If I set NGROUPS to 4, I get:
Note that, rather than using pipes and shell tricks, the script generates intermediate files so you can easily see each stage of the processing in order to debug it.
For example, if you run this:
you will see the output that
convert
is passing toawk
:If you look at
groupHSL-sorted.txt
, you will see how the pixels have been sorted into groups and then increasing lightness:Windows is particularly awkward at quoting things - especially scripts in single quotes like I use above for
awk
. I would suggest you extract the two separateawk
scripts into separate files something like this:script1.awk
and
script2.awk
Then the two lines in the main script will become something like:
and