Graphics File Formats
Working with Graphics Files
There are a number of common graphics file formats that have been used
to save image data.
Usually, there is a "header" at the beginning of the file that
contains information about the image such as file type and the dimensions
for the graphic image. After that, the data telling what the graphic looks
like is listed. For some file formats, the color data is given very clearly
with RGB (red, green, blue) components clearly listed for color images, or
just a single value representing the gray level for grayscale images.
In other file types, the
data is compressed and difficult to access.
The image displayed to the right is a copy of a watercolor
painting done by this teacher, and will be used as a subject for various
image processing functions presented here. It is in JPG format
which does utilize compression.
Common File Formats Using Data Compression:
- GIF - Better for images that have large regions of the same few colors. GIF uses a patented algorithm for data compression called "LZW", so applications that convert to GIF images must pay Unisys a royalty.
- PNG - Portable Network Graphic file format, a replacement for GIF since there are no problems with the patent.
- JPG - Better for photographic type images that have many colors and
delicate shading. This is considered a "lossy" graphic compression
technique because some of the original data is lost in the compression
process. The data loss is usually not too much of a concern though.
Common File Types Using No Compression:
- TIFF - File ends in ".tif" Very common scan type that maintains
all of the data without information loss.
- Targa - File ends in ".tga" Same data as above, but different header
information. This file type can be compressed with certain options.
- PPM - File ends in ".ppm" - Data is usually written in "raw" format
where each pixel is represented by three separate characters for the "RGB"
components. However, there is also an option to save in ASCII format where a
three digit integer ranging from 0 to 255 is used to represent each color
component. Note that the file order is "RGB", but be careful about line feeds
and carriage returns in the header so that the order of character data is not
offset improperly as I did on my first attempt.
- PGM - Gray scale version of PPM where only one component is
used for each of the pixels.
For more information on these latter file formats, check out:
Image Processing Techniques
There are anumber of interesting techniques that allow one to access
the information in a graphics file, and then modify the data to view
it differently. For this project, you will be expected to create
your own image processing algorithm. You may need to read the data
into a two-dimensional array, and then compare adjacent neighbors
defore writing a character to disk. Everyone in the class should
create their own image processing algorithm.
To compare the effects of just a few simple algorithms, take a look
atthe following examples. These just require reading data from the
original file, and then writing a new character into the output file.
- Black and White Silhouette
If (Color < SomeValue)
Color = Black
Color = White
Black and White
Color = (255 - Color)
- Edge Detection
Horizontal Edge Algorithm|
Read Color1, Color2
If (abs(Color1 - Color2) > SomeValue)
Color2 = Black
Color2 = White
- Colored Regions
Read Color (R,G,B)
If (Color == MostlyRed (R) )
Color = Red (255,0,0)
If (Color == MostlyGreen (G))
Color = Green (0,255,0)
Color = White (255,255,255)
- Some Other Algorithms:
AI Class Worksheet #9B
- Edge Detection Algorithms from TJ's AI Classes
Algorithms for Image Processing - Dutch Website
efg's Computer Lab Reference Library
- Lots of links to algorithms