0
votes

The raytracer we're programming generates simple PPM image files. We wrote a little something that generates scene definitions for us, so that we can create an animation with these files.

The initial workflow was opening all files in Photoshop via File > Scripting > Load Files into Stack and exporting the result as a gif. This works well, although the workflow is bumpy. The quality is good, the file size huge.

Now when using ImageMagick to convert from PPM to GIF, the quality of the resulting image is horrible. That is, the quality of single GIF files produced by ImageMagick is already bad. Combining them to a GIF of course does not change that.

Original File (saved as PNG with Photoshop):

Test file saved as PNG with Photoshop

GIF (converted from PPM with ImageMagick):

Test file converted from PPM with ImageMagick

(Especially notice the spots around the point where the light emits)

I just used mogrify -path ../gif -format gif 006.ppm for that result. I don't really know where to start to tweak this (although I played around with a couple of options from the reference).

Further Notes:

  • For reference, here are some example files (original ppm file, ImageMagick gif, …) to play with: https://github.com/kleinfreund/raytracer/tree/master/assets
  • Quality is very good when exporting a single image via Photoshop (selective, diffuse dither 100%, no transparency, 256 colors, no meta data)
  • Quality is also very good when batch-converting the PPM files to PNG with ImageMagick
  • I'm open to other workflows, so I'm fine if you can provide an alternative solution as well

Comparison 1

(a little animation of the difference between the two files so the issues are easier to see. by Mark Setchell)

Comparison 2

1
Sorry, I find your question quite confusing. Are you saying that you get bad quality when you use ImageMagick to convert a PPM to a GIF - if so, please give us the PPM and the GIF you get. Or are you saying when you combine multiple PPMs into a GIF then you get bad quality - if so, please give us the multiple PPMs and the GIF. I don't really understand what Photoshop or PNG have to do with it. - Mark Setchell
@MarkSetchell Thanks for the feedback. I'll update the question and provide the related ppm file in a moment. So, currently the conversion to single GIF files is already bad. Not speaking about the animation I want to produce, yet. Also, the reason why I provided the png file is that the ppm file can't be displayed as easily. - kleinfreund
@MarkSetchell I added some example files (including the ppm file) to our repository: github.com/kleinfreund/raytracer/blob/master/assets - kleinfreund

1 Answers

2
votes

Other Option

Another option may be to convert to MPG format, something like this:

convert -delay 1 a-*png m2v:movie.mpg

or

convert -delay 1 a-*ppm m2v:movie.mpg

Updated Answer

I see - you have to use GIF for your animation, so PNG is not an option. Maybe you can quantize in a different colourspace, e.g. like this for Lab colorspace:

convert orig.ppm -quantize Lab -colors 256 result.gif

Other options might be YUV, RGB - you can get a list of all options with

identify -list colorspace

Original Answer

The problem is that your PPM file has more colours than the GIF format can contain. You can count the colours used like this:

convert orig.ppm -print "%k\n" null:
642

which shows your image has 642 colours.

The GIF format ony allows a palette of 256 colours - reference. Can you use PNG format instead?