Page 1 of 1

Converting an animated gif to a custom grayscale image

Posted: 2015-02-09T21:47:27-07:00
by KenBurns
Hi all, I've been racking my brain the last few days trying to get this to work and keep running into problems. I'm try to convert an animate gif to a 8-bit grayscale format with a custom color mapping. Essentially the grayscale file is every frame of the animated gif converted to the custom 8-bit mapping, and each frame is just appended to the previous one.

I'm able to do a standard grayscale conversion to get my basic output using:

convert out.gif -append out.gray

However this uses the standard grayscale intensity settings to convert which isn't what I need. However it does convert all the frames of the animated gif and append them to the output file correctly.

Since I need a custom color mapping, I'm using the -fx operator to do this.

convert out.gif -fx "((b*256)&224)/256 + ((g*256)&224)/2048) + ((r*256)&192)/16384)" -append out.gray

However, this only converts the very first frame of the animated gif. How can I do this to convert all frames of the gif?

Any thoughts?

Thanks,

Ken

Re: Converting an animated gif to a custom grayscale image

Posted: 2015-02-09T21:49:52-07:00
by fmw42
try adding -coalesce

Code: Select all

convert out.gif -coalesce -fx "((b*256)&224)/256 + ((g*256)&224)/2048) + ((r*256)&192)/16384)" -append out.gray

Re: Converting an animated gif to a custom grayscale image

Posted: 2015-02-10T08:24:49-07:00
by KenBurns
Thanks - I've tried to add -coalesce but it's still the same output and didn't fix the issue, it just gives the first frame from the animated gif.

Thanks,

Ken

Re: Converting an animated gif to a custom grayscale image

Posted: 2015-02-10T11:45:09-07:00
by fmw42
Yes, -fx only works on the first image in the command line, unless you reference each by u[...]. But I do not think that helps here.

But you can do this loop. Unix syntax.

Code: Select all

num=`convert anim.gif -coalesce -format "%s\n" info: | tail -n 1`
echo $num
for ((i=0; i<=num; i++)); do
convert anim.gif[$i] -fx "((b*256)&224)/256 + ((g*256)&224)/2048) + ((r*256)&192)/16384)" miff:-
done | convert - +append out.png

Re: Converting an animated gif to a custom grayscale image

Posted: 2015-02-10T15:47:25-07:00
by KenBurns
Thanks - I was able to get it to work using a shell script like you showed.

Thanks!

Ken