ImageMagick

From ACENET
Jump to: navigation, search

ImageMagick

Description
ImageMagick is a software suite to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
Modulefile
imagemagick
Documentation
ImageMagick homepage
ImageMagick supported formats

FFmpeg

Description
FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video.
Modulefile
ffmpeg
Documentation
FFmpeg homepage

Image manipulation

Let's consider a directory with ten files (images) in the PNG format: riB_001az.png ... riB_010az.png.

First, load the imagemagick modulefile like so:

$ module load imagemagick

To view a file, you can use

$ display riB_001az.png

To view an animation of several images:

$ animate *.png

The following command will tell you about the image. For example, you can see that it's compressed (losslessly with zip):

$ identify -verbose riB_001az.png

To convert a single file to a different format:

$ convert riB_001az.png riB_001az.jpeg
$ convert riB_001az.png riB_001az.gif

Convert all PNG files into TIFF:

$ mogrify -format tiff *.png

For the next commands make sure you have loaded the ffmpeg modulefile like so:

$ module load ffmpeg

You can also use convert to create a movie like so:

$ convert *.png movie.mpg

If you do not have many frames then it's often useful to introduce a delay:

$ convert -delay 10 *.png movie.mpg

The ImageMagick convert command may not be as flexible at creating movies as ffmpeg itself. This is how you can use ffmpeg directly to create a movie for Windows

$ ffmpeg -r 5 -i riB_%03daz.png movie.avi

or Mac

$ ffmpeg -r 5 -i riB_%03daz.png movie.mp4

Please note that you cannot use *.png in the above command to list the image files, as it will result in only one frame put into the movie, and the rest of the png files being overwritten. Use the C-style syntax instead. The option -r 5 slows down the animation to 5 frames a sec, which is useful when you only have 10 frames to show.

Handling raw data formats

If you have a raw binary data file that contains a 512x512 image with the grey scale color representation of one-byte integer per pixel then you can convert it into a PNG image like so:

$ convert -size 512x512 -depth 8 gray:riB_001az riB_001az.png

Note that ImageMagick also allows processing raw binary files containing floating-point numbers.

Clean-up for the next step:

$ rm *.png

In order to convert all ten raw data files into PNG:

$ mogrify -size 512x512 -depth 8 -format png gray:riB_00*

Now you can animate them to see the result

$ animate ri*.png

And make a movie with either command:

$ ffmpeg -r 5 -i riB_%03daz.png movie1.avi
$ convert -delay 10 ri*.png movie.mpg

Clean-up for the next step:

$ rm *.png movie*

To make a movie in one step from the raw data files:

$ convert -delay 10 -size 512x512 -depth 8 gray:riB_0* movie.mpg

Working with a palette

Now, the grayscale palette may be boring, so here is how you can colorize it.

Clean-up for the next step:

$ rm *.png movie*

Create a palette

$ convert -size 1x100 gradient:wheat-brown gradient:brown-lawngreen gradient:dodgerblue-navy -append -flip palette.png

Create one colorized PNG from a raw data file:

$ convert -size 512x512 -depth 8 gray:riB_001az palette.png -clut riB_001az.png

Create colorized PNGs from raw data files:

$ for i in riB_*az; do convert -size 512x512 -depth 8 gray:${i} palette.png -clut ${i}.png; done

Make a movie with either command:

$ ffmpeg -r 5 -i riB_%03daz.png movie.avi
$ ffmpeg -r 5 -i riB_%03daz.png movie.mp4
$ convert -delay 10 ri*.png movie.mpg