Palettes
Palette images save image space by reducing the number of colors used in the image to 256
colors and then using one number per pixel (one channel) to specify the color for
each pixel. Each color number corresponds to a color in a palette of 256 colors. Each color in the palette is a True Color RGB color out of a
possible range of millions of colors.
Manifold uses the terms "palette images" and "palettes" because those are the
terms used in Microsoft standard applications such as Microsoft Photo Editor
and Microsoft Office. Non-Microsoft graphics packages and legacy GIS
applications may use different terms. For example, palette images are known as Indexed Color mode images in Adobe PhotoShop and palettes are called color tables or color maps in some applications.
Palette images have become less important for graphics editing in modern times
because the cost of disk drive space has plummeted. In an era when cheap disk
drives deliver tens of gigabytes it is no longer as important as it used to be
to reduce the space consumed by images. Preserving high visual quality is
usually much more important with most images than saving space.
The exceptions are massive raster data images that originate in various
technical programs, which may be tens or even hundreds of megabytes in size.
Reducing the size of such images by converting them to palette images is often a wise
trade-off between quality and size.
Another reason for use of palette images is that many images are published in
formats that use palettes. Manifold supports fine control over palette images
and the palettes they use to allow maximum exploitation of such images.
Another reason to use palette images is to reduce the size of images that will
be published on Internet. Even with fast connections, Internet is so slow
that it is very important to reduce the size of images used on web sites.
Reducing the number of colors in an image allows web graphics formats such as .gif and .jpg the best possibilities of compressing the image to a small size.
Finally, an important raster data usage of palettes is to force pixels into a
pre-defined set of color values. Such values can represent various
classification schemes for the physical regions represented by the pixels or other data
values.
About Palette Images
RGB images use three numbers per pixel to specify the colors in an image.
Using three numbers per pixel allows about 16 million color combinations in most
installations but it requires a lot of storage space for each image. As
mentioned in the RGB Images and Channels topic there have been many methods invented for reducing the size of RGB
images.
One method noted uses one number per pixel by averaging brightness for all
three pixels to provide a single, grayscale number for each pixel. This is very
compact for storage, but it loses all non-grayscale colors in the image.
Another popular method for reducing the size of RGB images is to use a palette. This method will preserve good color appearance in many cases while
dramatically reducing the size of the image.
The palette method depends on the observation that most RGB images use only a
small number of the 16 million possible colors available for use. There are
two reasons why this is so. The first reason is that most images have far fewer
than 16 million pixels in them. A 1024 x 768 image, for example, has less
than a million pixels. Even if each pixel were a different color such an image
would require much less than 16 million different colors to draw.
The second reason is that most colors used in computer images are so similar
to each other that they are indistinguishable to the human eye. An example:
If we zoom far into our example bronze image near the head and chin of the monument we can see that the blue sky is
composed of many blue pixels that are slightly different shades of blue.
However, most of the blue shades are so similar to each other that it is very
difficult to tell them apart. We could easily replace the hundreds of different, but
virtually identical, shades of blue with two or three "blues" without
significantly changing the appearance of the image.
That's exactly what the palette method does: to convert an RGB image into a
palette image the system analyzes all RGB colors in the image and groups them
into similar shades. The palette method then takes all the very similar colors in
a group and replaces them with one color that is a close match to all of the
colors in that group. For many images, it is possible to choose only 256
colors that are so reasonably close to the various similar colors out of all 16
million possible colors that the image appears the same as the original.
To see this in action, consider the above two images. Both images are zoomed
in views of the bronze sample image showing the head and chin of the bronze monument. The image at
left uses three RGB numbers per pixel so that each pixel can be any one of 16
million possible colors. Note how the blue sky is composed of many similar
shades of blue, most of which are indistinguishable from each other.
The image on the right uses only 32 colors throughout the entire image. Each of these 32 colors is an RGB color
chosen from the overall range of 16 million colors to be the best match
possible to the group of similar colors it replaces. Only two shades of blue, for
example, appear in the blue sky. We use 32 colors in this example because using
256 colors as is normally done with palette images results in such a close match
to the original image that it is hard to tell the difference. Using 32 colors
makes differences more apparent for the sake of an example.
The palette method saves the reduced number of colors in a palette (also known as a color table or color map) which is to be used for that image. Each color in the palette is listed as
a three-number RGB color. The 32-color palette for the sample bronze image converted to 32 colors (part of which is shown above), for example, is:
Using only the above 32 colors results in an image that is remarkably close to
the original.
The image on the left is the original, while the image on the right is the
32-color image.
How Palettes Work
Palette images in Manifold use 256 colors per image. This makes it possible
to save images using only one byte per pixel, since each byte can represent 256
colors (bytes range in value from 0 to 255 for 256 positions in all). The
first step in converting an RGB image is reducing it to 256 colors as described
above. This requires picking out a palette that is a "best match" to the many
colors in the RGB image and then assigning a color from the palette to each
pixel in the image. Each pixel then is represented with one number that specifies
which color in the palette is to be used for that pixel. All this is done
automatically in one step by the Image - Convert To dialog when it converts an RGB image to a palette image.
For programmers: Palette images have one byte per pixel where the byte is an index into the
palette. The palette is just a look-up table that says what RGB value is to be
used for that pixel. That is why Adobe PhotoShop refers to such images as "Indexed Color" images.
Let's take a look at how the example 32-color bronze image might be saved as a
palette image.
The pixels in the region enclosed in red in the illustration would be coded as
one number per pixel:
The number for each pixel says which color in the palette to use for that
number. To figure out what color the number 16 in red shown above is supposed to be, we look at the palette used for this
image:
All the colors used in this image are listed in the palette.
The look-up process is simple: the number 16 takes us to the sixteenth color in the palette, which is a shade of blue
specified by the RGB triplet of numbers 91, 143, 207. These three numbers will be
used to control the RGB pixel elements in the computer monitor for that
specific pixel.
Note that the pixel to the right of the one shown in red has the value 18, which is a lighter shade of blue, the eighteenth color in the palette, two
slots over from 16.
A Useful Analogy
If the above sounds confusing, perhaps a Liberal Arts analogy will help. Many
people during their childhood have had exposure to "paint by numbers" kits.
These kits provide white drawing boards that are covered with faint lines
denoting regions that are to be filled with paint. Each region has a number in it.
The numbers correspond to a collection of paint colors that are provided
with the kit. Each color has a number. The child's task is to paint each
region with the color paint corresponding to the number in that region. For
example, all number 5 regions should be colored using paint from the number 5
container, which might be red. If done carefully the result will be a reasonable
picture.
In classical artistic circles, the word "palette" means the board with colors on it that a painter holds in his or her hand.
The painter chooses colors from the palette to load onto a brush that applies
those colors to the canvas. Some painters in art history had a preference for
using a particular selection of colors on their palettes and so the word
"palette" in art history has also come to mean a particular collection of colors
favored by a painter. One can speak of the distinctive palette of Cézanne, for
example, or one might compare the sepia palette used by Van Gogh in his early
work with the vivid palette he employed late in life in Arles.
In a paint-by-numbers kit the palette is the numbered set of paint colors.
Palette images in computers are like the drawing boards in a paint-by-numbers
kit where the number at each spot says which dab of paint to apply at that spot.
It's obviously a lot more economical to code each spot with a single number
than to write out "Ocher Brown" at one spot and "Goldenrod Yellow" at another.
The analogy is even more useful if we recall another childhood incident we may
have experienced or heard about. Suppose in the coloring-in of our
paint-by-numbers kit we get confused and think that the number 5 means to paint in a blue
color and not the red color. The result will be that throughout the entire
image we have switched the palette color for red with blue. In Manifold, such
changes in palette colors are something that may be deliberately done with
palette images in order to achieve desired color effects.
Images and their Palettes
Each image that is a palette image will have an associated palette that it
uses. In Hierarchy view, the project will show each palette underneath the image it serves.
Note that a logical outcome of the palette method for images is that for
photographic or visual rendering the palette used with each particular image is
specific to that image. The particular set of 256 colors that does the best job
of approximating colors in one RGB image will not be the same as the 256 colors
used to best approximate a different image.
For example, the sample bronze image is mostly greens and blues so the 32-color palette for this image shown
above has many different shades of green and blue.
The sample image of tokyo airport, on the other hand, would use an entirely different palette that has
many shades of near-black color when reduced to 32 colors.
Changing Palettes
Most graphics editors either do not show palettes that are used by palette
images or they bury access to the palette deep within specialized menus. They do
this because it is rare that one changes the palette in a photographic image
that is only intended to provide a good visual appearance to the human eye.
Images in a GIS environment are often used for other purposes besides providing a
natural, photographic view of a scene. We will want to change palettes
sometimes for such other purposes. Manifold System therefore provides the palettes
used with images as separate components immediately at hand in the project pane.
We may wish to change palettes to achieve sophisticated image effects with
visual images or to better represent data that is shown as a raster data image
using a palette. Raster data images, for instance, are often created from
multi-channel satellite images using "false" color to show data in the satellite
scans. The colors used in a palette for such images might be arbitrary choices
intended to show data in some range. For example, a palette image might show
temperatures at particular locations using a palette where the colors range from
blue to green to yellow to orange to red to show an increasing temperature
range.
When working with such images in a GIS environment Manifold makes it easy to
pop open the palette used in a palette window if changes to the palette colors
are desired. For example, one might wish to change the colors in the
temperature range palette so that the very coldest colors are all blues and the very
hottest values are all reds with nothing but one shade of gray in between. To do
this we would select all the colors between red and blue in the palette and
change them to gray. All pixels in the image that were colored using those palette
colors would instantly switch to gray. It's just like changing the paint
containers in a paint-by-numbers kit.
Double click on a palette component to open it in a palette window. Make any
changes by clicking into the color wells for individual colors and changing
the colors. All standard Manifold selection methods will work when selecting
colors in the palette window. See the Editing Palettes topic for an example.
Any changes made to a palette will immediately be applied to the image that
uses that palette.
Palette Sizes and Image Sizes
Using a palette involves adding about 1000 bytes to the image size to save the
palette lookup table (256 palette positions having three numbers each adds up
to 768 bytes). For images that are thousands or millions of bytes in RGB
form that is a big economy because investing 1000 bytes into a palette cuts the
image size down by two-thirds at least. Some image formats using palettes can
compress the image size even further if the image is exported into those
formats.
Manifold palettes are always 256 color palettes. Images may be adjusted so
they use fewer than 256 colors out of the palette. The main reason for using
fewer than 256 colors is to simplify data management when using palettes with
false color raster data images. It's easier to assign different colors if there
are only 8 colors, say, in our range of temperatures for a raster data image
than if we need to assign 256 colors for different temperatures.
Although there is no savings in image space used within the Manifold project
if an image uses fewer than 256 colors, using fewer colors may result in space
savings if the image is exported to certain formats. Some graphics formats, such
as GIF, will automatically compress the image to a smaller size if the number
of color changes is fewer. Keeping the size of the image as small as possible
is important when creating images for use on web sites, where every byte of
the image must be flung down a potentially very slow Internet connection.
Using as few colors as possible will give the web image format used the best
chance of compressing the picture when it is exported for use as a web image.
Another way of keeping images as small as possible for web use is to use a standard palette, such as the standard web browser palette.
Standard Palettes
The use of palette images is so widespread that operating systems and web
browsers are set up to exploit their use.
Although using a palette always provides big savings in space with large
images, when images are very small the thousand bytes required for the palette
becomes a significant percentage of the total size of the image. For example, one
thousand extra bytes are a lot of bytes if the image itself is only a 32 x 32
icon (1024 bytes). In an operating system where numerous small images may
occur it would be very inefficient if each small image had to carry its own
palette around with it. To avoid this inefficiency Microsoft Windows includes a
standard palette that is built into the operating system. Images that use the
standard palette don't have to include a copy of their palette. They simply use
the operating system palette.
Many web pages include numerous small images used as buttons or other
graphical elements. If each used a unique palette, the size of such images could
effectively double. To economize on download bandwidth all Internet web browsers
include the same, standard palette for use by web pages. Using the standard web
palette for small images destined for a web site will often reduce their size.
Unfortunately, since the first web browsers were designed by people who were
oblivious to the interests of the general computing public a different palette
is used in web browsers than that made standard by Windows.
Both the web palette and the Windows palette incorporate a selection of colors
that will work reasonably well for most images. Neither will work quite as
well as a palette adapted specifically to a particular image but both will often
work well enough for operating system or web use. Manifold's Image - Convert To dialog for creating palette images provides a list box that allows choice of
a standard palette if one is desired. If a standard palette is selected the
image will automatically be converted using only those colors that are in the
palette selected. Standard palettes include both Windows and web palettes. For
those with a sense of humor there is even an option to use the Mac system
palette.
Importing / Exporting Palette Images
Some graphics image formats use palettes and some do not. When importing an
image from a format that uses palettes Manifold will automatically import and
create a palette component for the image.
When exporting to a format that uses palettes Manifold will combine the image
and palette components in the correct way for storage within that format. The
palette used with each image is embedded within the image file for all
standard graphics formats that use palettes.
Creating a Palette Image
Palette images and their palettes are created automatically when importing
from a graphics format that uses palettes. Palette images may also be created by
converting from grayscale, RGB or RGBa images.
Use the Image - Convert To dialog to convert an image into a palette image. A choice of conversion
methods and standard palettes will appear in the Palettes list box.
When to Use and Not to Use Palettes
It is important to understand that converting an RGB image into a palette is a
permanent change in the data of the image. An image that formerly could
have consisted of as many different colors as there are pixels in the image (up to
a total of about 16 million different colors) will be simplified into using
only 256 colors.
Reducing an image to only 256 colors will often result in negligible change in
visual appearance. However, certain finely detailed images will lose
vividness and may get a granular appearance in regions of smooth color gradient
changes. If images must retain as much visual quality as possible it is best not to
convert them to palette images. Images destined for enlargement or
professional printing should never be converted.
Not all image commands will work in palette images. For example, Hue / Saturation depends on having three RGB channels for fine control of shades and will not
work in one channel images such as palette images.
When creating complex images using RGBa transparency and other sophisticated
effects all editing should be done using RGB or RGBa images. Only after the
final image is ready should one consider converting it to a palette image and
then only if it is destined for publication on the web. In an era of very
inexpensive disk drives that deliver many tens of gigabytes of storage it is more
important to keep visual quality high in photographic images than it is to save
disk space.
Many raster data images in the mapping world originated as raster data sets in
circumstances where each pixel's data had some scientific importance.
Despite their technical origin such raster images often end up being used in a purely
visual way where the specific data attached to each pixel is no longer
important. Such images in their original raster data form can be enormous, with
sizes in the hundreds of megabytes. It's a good idea to convert such images to
palette images to save space and to increase system performance.
However, if the multi-channel data for each pixel continues to be important
for some analytic purpose they should not be converted since doing so will
destroy the data.
Notes
The above examples are written as if the "original" images use 16 million
colors and the palette images are 32 colors. In fact, all images that appear in
this Help file have been reduced to at most 256 colors due to limitations of the
Windows Help system. Using 256 colors to represent the "16 million-color"
images nonetheless results in such a good effect that we still had to use 32 color
examples for palettes in order for the effects of conversion to be obvious.
The numbers in the palette example were made up by glancing at the image and
estimating what the numbers should look like inside the image. They show the
idea and relationships correctly but should not be taken as the exact numbers
that will appear when the bronze image is converted into a 32-color palette image.
Back to Manifold Home Page