ImageMagick Version 7 • High Dynamic Range Imaging • Pixel Channels • Alpha • Grayscale • Masks • MagickCore API • Header Files • Deprecated Features Removed • Command-line Interface • Version 7 Change Summary
The design of ImageMagick is an evolutionary process, with the design and implementation efforts serving to influence and guide further progress in the other. With ImageMagick version 7 we aim to improve the design based on lessons learned from the version 6 implementation. ImageMagick was originally designed to display RGB images to an X Windows server. Over time we extended support to RGBA images and then to the CMYK and CMYKA image format. With ImageMagick version 7, we extend support to arbitrary colorspaces with an arbitrary number of pixel channels. Other design changes are in the works and we will document them here so be sure to revisit periodically.
To support variable pixel channels in the MagickCore API, pixel handling has changed when getting or setting the pixel channels. You can access channels as an array, pixel[i], or use an accessor method such as GetPixelRed() or SetPixelRed(). There are some modest changes to the MagickCore and MagickWand API's. The Magick++ and PerlMagick API's have not changed and matches that of the ImageMagick version 6.
The shell API (command line) of ImageMagick version 7 is also undergoing a major overhaul, with specific emphasis on the ability to read 'options' not only from the command line, but also from scripts, and file streams. This allows for the use of 'co-processing' programming techniques or performing image handling using 'deamon/server backends', and even multi-machine distributed processing.
With shell API overhaul other improvements are being made, including: better reporting of which option failed, the consolidation and deprecation of options, and more global use of 'image properties' (more commonly known as 'percent escapes' in option arguments.
ImageMagick version 7 is available now as an Beta release. Look for an official release around 1st Q 2016. An official ImageMagick version 7 release depends on how smoothly the Beta cycle progresses. During the Beta cycle, version 6 developers can attempt to port their software to version 7.
Once ImageMagick version 7 is released, we will continue to support and enhance version 6 for a minimum of 10 years.
ImageMagick version 7 enables high dynamic range imaging (HDRI) by default. HDRI accurately represents the wide range of intensity levels found in real scenes ranging from the brightest direct sunlight to the deepest darkest shadows. In addition, image processing results are more accurate. The disadvantage is it requires more memory and may result in slower processing times. If you see differences in the results of your version 6 command-line with version 7, it is likely due to HDRI. You may need to add -clamp
to your command-line to constrain pixels to the 0 .. QuantumRange range, or disable HDRI when you build ImageMagick version 7. To disable HDRI (recommended for smart phone builds such as iOS or production sites where performance is a premium), simply add --disable-hdri
to the configure script command line when building ImageMagick.
A pixel is comprised of one or more color values, or channels (e.g. red pixel channel).
Prior versions of ImageMagick (4-6), support 4 to 5 pixel channels (RGBA or CMYKA). The first 4 channels are accessed with the PixelPacket data structure. The structure includes 4 members of type Quantum (typically 16-bits) of red, green, blue, and opacity. The black channel or colormap indexes are supported by a separate method and structure, IndexPacket. As an example, here is a code snippet from ImageMagick version 6 that negates the color components (but not the alpha component) of the image pixels:
for (y=0; y < (ssize_t) image->rows; y++)
{
register IndexPacket
*indexes;
register PixelPacket
*q;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
{
status=MagickFalse;
continue;
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
for (x=0; x < (ssize_t) image->columns; x++)
{
if ((channel & RedChannel) != 0)
q->red=(Quantum) QuantumRange-q->red;
if ((channel & GreenChannel) != 0)
q->green=(Quantum) QuantumRange-q->green;
if ((channel & BlueChannel) != 0)
q->blue=(Quantum) QuantumRange-q->blue;
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
indexes[x]=(IndexPacket) QuantumRange-indexes[x];
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
}
ImageMagick version 7 supports any number of channels from 1 to 32 (and beyond) and simplifies access with a single method that returns an array of pixel channels of type Quantum. Source code that compiles against prior versions of ImageMagick requires refactoring to work with ImageMagick version 7. We illustrate with an example. Let's naively refactor the version 6 code snippet from above so it works with the ImageMagick version 7 API:
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
*q;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
{
status=MagickFalse;
continue;
}
for (x=0; x < (ssize_t) image->columns; x++)
{
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
SetPixelRed(image,QuantumRange-GetPixelRed(image,q),q);
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
SetPixelGreen(image,QuantumRange-GetPixelGreen(image,q),q);
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
SetPixelBlue(image,QuantumRange-GetPixelBlue(image,q),q);
if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
SetPixelBlack(image,QuantumRange-GetPixelBlack(image,q),q);
if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
SetPixelAlpha(image,QuantumRange-GetPixelAlpha(image,q),q);
q+=GetPixelChannels(image);
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
}
Let's do that again but take full advantage of the new variable pixel channel support:
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
*q;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
{
status=MagickFalse;
continue;
}
for (x = 0; x < (ssize_t) image->columns; x++)
{
register ssize_t
i;
if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
PixelChannel channel=GetPixelChannelChannel(image,i);
PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
q[i]=QuantumRange-q[i];
}
q+=GetPixelChannels(image);
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
}
Note, how we use GetPixelChannels() to advance to the next set of pixel channels.
The colormap indexes and black pixel channel (for the CMYK colorspace) are no longer stored in the index channel, previously accessed with GetAuthenticIndexQueue() and GetCacheViewAuthenticIndexQueue(). Instead they are now a first class pixel channel and accessed as a member of the pixel array (e.g. pixel[4]
) or with the convenience pixel accessor methods GetPixelIndex(), SetPixelIndex(), GetPixelBlack(), and SetPixelBlack().
As a consequence of using an array structure for variable pixel channels, auto-vectorization compilers have additional opportunities to speed up pixel loops.
You can access pixel channel as array elements (e.g. pixel[1]
) or use convenience accessors to get or set pixel channels:
GetPixela() SetPixela()
GetPixelAlpha() SetPixelAlpha()
GetPixelb() SetPixelb()
GetPixelBlack() SetPixelBlack()
GetPixelBlue() SetPixelBlue()
GetPixelCb() SetPixelCb()
GetPixelCr() SetPixelCr()
GetPixelCyan() SetPixelCyan()
GetPixelGray() SetPixelGray()
GetPixelGreen() SetPixelGreen()
GetPixelIndex() SetPixelIndex()
GetPixelL() SetPixelL()
GetPixelMagenta() SetPixelMagenta()
GetPixelReadMask() SetPixelReadMask()
GetPixelWriteMask() SetPixelWriteMask()
GetPixelMetacontentExtent() SetPixelMetacontentExtent()
GetPixelOpacity() SetPixelOpacity()
GetPixelRed() SetPixelRed()
GetPixelYellow() SetPixelYellow()
GetPixelY() SetPixelY()
You can find these accessors defined in the header file, MagickCore/pixel-accessor.h
Each pixel channel includes one or more of these traits:
We provide these methods to set and get pixel traits:
GetPixelAlphaTraits() SetPixelAlphaTraits()
GetPixelBlackTraits() SetPixelBlackTraits()
GetPixelBlueTraits() SetPixelBlueTraits()
GetPixelCbTraits() SetPixelCbTraits()
GetPixelChannelTraits() SetPixelChannelTraits()
GetPixelCrTraits() SetPixelCrTraits()
GetPixelGrayTraits() SetPixelGrayTraits()
GetPixelGreenTraits() SetPixelGreenTraits()
GetPixelIndexTraits() SetPixelIndexTraits()
GetPixelMagentaTraits() SetPixelMagentaTraits()
GetPixelRedTraits() SetPixelRedTraits()
GetPixelYellowTraits() SetPixelYellowTraits()
GetPixelYTraits() SetPixelYTraits()
For convenience you can set the active trait for a set of pixel channels with a channel mask and this method:
SetImageChannelMask()
Previously MagickCore methods had channel analogs, for example, NegateImage() and NegateImageChannels(). The channel analog methods are no longer necessary because the pixel channel traits specify whether to act on a particular pixel channel or whether to blend with the alpha mask. For example, instead of
NegateImageChannel(image,channel);
we use:
channel_mask=SetImageChannelMask(image,channel);
NegateImage(image,exception);
(void) SetImageChannelMask(image,channel_mask);
In version 7, we introduce pixel user channels. Traditionally we utilize 4 channels, red, green, blue, and alpha. For CMYK we also have a black channel. User channels are designed to contain whatever additional channel information that makes sense for your application. Some examples include extra channels in TIFF or PSD images or perhaps you require a channel with infrared information for the pixel. You can associate traits with the user channels so that they when they are acted upon by an image processing algorithm (e.g. blur) the pixels are copied, acted upon by the algorithm, or even blended with the alpha channel if that makes sense.
In version 7, we introduce pixel metacontent. Metacontent is content about content. So rather than being the content itself, it's something that describes or is associated with the content. Here the content is a pixel. The pixel metacontent is for your exclusive use (internally the data is just copied, it is not modified) and is accessed with these MagickCore API methods:
SetImageMetacontentExtent()
GetImageMetacontentExtent()
GetVirtualMetacontent()
GetAuthenticMetacontent()
GetCacheViewAuthenticMetacontent()
GetCacheViewVirtualMetacontent()
We support alpha now, previously opacity. With alpha, a value of 0 means that the pixel does not have any coverage information and is transparent; i.e. there was no color contribution from any geometry because the geometry did not overlap this pixel. A value of QuantumRange
means that the pixel is opaque because the geometry completely overlapped the pixel. As a consequence, in version 7, the PixelInfo structure member alpha has replaced the previous opacity member. Another consequence is the alpha part of a sRGB value in hexadecimal notation is now reversed (e.g. #0000 is fully transparent).
The Rec601Luma
and Rec709Luma
colorspaces are no longer supported. Instead, specify the gray
colorspace and choose from these intensity options:
Rec601Luma
Rec601Luminance
Rec709Luma
Rec709Luminance
For example,
convert myImage.png -intensity Rec709Luminance -colorspace gray myImage.jpg
Previously, grayscale images were Rec601Luminance and consumed 4 channels: red, green, blue, and alpha. With version 7, grayscale consumes only 1 channel requiring far less resources as a result.
Version 7 supports masks for most image operators. Black pixels in a read mask ignores corresponding pixel in an image whereas black pixels in a write mask protects the corresponding pixel in the image. From the command-line, you can associate a mask with an image with the -read-mask
and -write-mask
options. This polarity is the reverse of masks in version 6 of ImageMagick. For convenience, we continue to support the -mask
option in version 7 to match the behavior of version 6.
In this example, we compute the distortion of a masked reconstructed image:
compare -metric rmse -read-mask hat_mask.png hat.png wizard.png difference.png
Here we protect certain pixels from change:
convert rose: -write-mask rose_bg_mask.png -modulate 110,100,33.3 +mask rose_blue.png
Here are a list of changes to the MagickCore API:
ExceptionInfo
argument to those methods that lacked it in version 6, e.g. NegateImage(image,MagickTrue,exception
);I
is now invariant
. I
conflicts with the complex.h
header.Here are a list of changes to the MagickWand API:
Prior versions of ImageMagick (4-6) reference the ImageMagick header files as magick/
and wand/
. ImageMagick 7 instead uses MagickCore/
and MagickWand/
respectively. For example,
#include <MagickCore/MagickCore.h>
#include <MagickWand/MagickWand.h>
All deprecated features from ImageMagick version 6 are removed in version 7. These include the Magick-config
and Wand-config
configuration utilities. Instead use:
MagickCore-config
MagickWand-config
The FilterImage() method has been removed. Use ConvolveImage() instead.
In addition, all deprecated MagickCore and MagickWand methods are no longer available in version 7.
As mentioned the primary focus of the changes to the Shell API or Command Line Interface is the abstraction so that not only can options be read from command line arguments, but also from a file (script) or from a file stream (interactive commands, or co-processing).
To do this the CLI parser needed to be re-written, so as to always perform all options, in a strict, do-it-as-you-see it order. Previously in IMv6 options were performed in groups (known as 'FireOptions), this awkwardness is now gone. However the strict order means that you can no longer give operations before providing an image for the operations to work on. To do so will now produce an error.
Error reporting is now reporting exactly which option (by argument count on command line, or line,column in scripts) caused the 'exception'. This is not complete as yet but getting better. Also not complete is 'regard-warnings' handling or its replacement, which will allow you to ignore reported errors and continue processing (as appropriate due to error) in co-processes or interactive usage.
The parenthesis options used to 'push' the current image list, and image
settings (EG: '(
' and ')
' ) on to a stack now has
a completely separate image settings stack. That is parenthesis 'push/pull'
image lists, and curly braces (EG: '{
' and '}
' ) will
'push/pull' image settings.
Of course due to the previously reported changes to the underlying channel handling will result be many side effects to almost all options. Here are some specific
Most algorithms update the red, green, blue, black (for CMYK), and alpha
channels. Most operators will blend alpha the other color channels, but other
operators (and situations) may require this blending to be disabled, and is
currently done by removing alpha from the active channels via
-channel
option. (e.g. convert castle.gif -channel RGB
-negate castle.png
).
Reading gray-scale images generate an image with only one channel. If
that image is to then accept color the -colorspace
setting needs to
be applied to expand the one channel into separate RGB (or other) channels.
Previously, command-line arguments were limited to 4096 characters, with ImageMagick version 7 the limit has increased to 131072 characters.
Here are a list of changes to the ImageMagick commands:
magick
" command is the new primary command of the Shell
API, replacing the old "convert
" command. This allows you to
create a 'magick script' of the form "#!/path/to/command/magick
-script
", or pipe options into a command "magick -script
-
, as abackground process. magick
", (only command name is different)
but which has an implicit "-script
" option. This allows you to
use it in an "env
" style script form. That is a magick script
starts with the 'she-bang' line of "#!/usr/bin/env
magick-script
" allowing the script interpreter to be found anywhere
on the users command "PATH
". This is required to get around
a "one argument she-bang bug" that is common on most UNIX systems
(including Linux, but not MacOSX).magick
utility. You can also invoke them from the magick
utility, for example, use magick convert logo: logo.png
to invoke the convert
utility.
Image settings are applied to each image on the command line. To associate a setting with a particular image, use parenthesis to remove ambiguity. In this example we assign a unique page offset to each image:
convert \( -page +10+20 first.png \) \( -page +100+200 second.png \) ...
By default, image operations such as convolution blends alpha with each channel. To convolve each channel independently, deactivate the alpha channel as follows:
convert ... -alpha discrete -blur 0x1 ...
To remove the alpha values from your image, use -alpha off
.
Some options have changed in ImageMagick version 7. These include:
-channel RGB
on your command line (e.g. -level-colors option).-gamma 1,2,3
) are no longer supported, instead use -channel
(e.g. -channel blue -gamma 2)
.ImageMagick version 7 supports these new options, though most are limited
to the "magick
" command, or to use in "magick
"
scripts.
(
' and ')
') is "-regard-parenthesis
" has
been set, just as in IMv6. Caution is advised to prevent un-balanced
braces errors.mogrify
" command to
explicitly separate the operations to be applied and the images that
are to be processed 'in-place'. (not yet implemented). However if
not provided, "-read
" can still be used to differentiate
secondary image reads (for use in things like alpha composition) from
the 'in-place' image being processed. -read
" (see below) of the next option as a image (as it was in
IMv6). exchange, extract, or copy one or more image channels.
The expression consists of one or more channels, either mnemonic or numeric (e.g. red or 0, green or 1, etc.), separated by certain operation symbols as follows:
<=> exchange two channels (e.g. red<=>blue)
=> copy one channel to another channel (e.g. red=>green)
= assign a constant value to a channel (e.g. red=50%)
, write new image with channels in the specified order (e.g. red, green)
; add a new output image for the next set of channel operations (e.g. red; green; blue)
| move to the next input image for the source of channel data (e.g. | gray=>alpha)
For example, to create 3 grayscale images from the red, green, and blue channels of an image, use:
-channel-fx "red; green; blue"
A channel without an operation symbol implies separate (i.e, semicolon).
Here we take an sRGB image and a grayscale image and inject the grayscale image into the alpha channel:
convert wizard.png mask.pgm -channel-fx '| gray=>alpha' wizard-alpha.png
Use a similar command to define a read mask:
convert wizard.png mask.pgm -channel-fx '| gray=>read-mask' wizard-mask.png
Add -debug pixel
prior to the -channel-fx
option to track the channel morphology.
magick
"
command to exit, without actually closing the pipeline that it is
processing options from. magick
" command
line, instead of a implicit output image, to completely prevent any image
write. ASIDE: even the "NULL:
" coder requires at least one
image, for it to 'not write'! This option does not require any images at
all. mogrify
" to allow the reading of
secondary images, and allow the use of image list operations within that
command. magick
", stop the processing of command line arguments as
image operations, and read all further options from the given file or
pipeline.These options are known to have changed, in some way.
-define convolve:bias=value
instead.matte
primitive is now alpha
(e.g. -draw 'alpha 0,0 floodfill'
).-draw "affine ..."
. (see transform)-evaluate-sequence Mean
.-undercolor
.-layers CompareAny
.-gaussian-blur
.-/+remap
.-/+read-mask
, -/+write-mask
.-alpha Set/Off
.-distort Affine "..."
.Almost 'plus' (+) option that did not do anything has been marked as deprecated, and does nothing. It does not even have associated code. For example "+annotate", "+resize", "+clut", and "+draw" .
-remap
.-evaluate-sequence Max
.-evaluate-sequence Median
.-evaluate-sequence Min
.-color-matrix
.-fill
.Changes from ImageMagick version 6 to version 7 are summarized here:
NegateImage(image,MagickTrue,exception);