PurposeThe purpose of this program, ShowImage.EXE, is to
show RGB, HSV, HLS, or CMYK color coordinates, planes and histograms of an image. YIQ
coordinates are displayed. A Print option allows the color separations or
histograms to be printed for R, G, B, H, S, V and Intensity. The number of unique
RGB colors in an image is counted.

Materials and Equipment

Software RequirementsWindows 95
Delphi 3 or 4 (to recompile)ShowImage.EXE
BMP, JPG, ICO, EMF, WMF file (GIFs can be used if you have a TGIFImage component.
See below.)

Double click on the magnifying glass icon, which represents the ShowImage.EXE
program.

Press the Read button and select an image to display. Press the Open button.
(The directory from where you select an image will be saved in an .INI file for your next
selection.)

Select the desired color space, RGB, HSV, HLS or CMYK from the ColorSpace
radiogroup. RGB color planes are shown as shades of of the color, or as shades of gray,
when the Monochrome checkbox is selected. The Hue plane is shown with fully
saturated colors. Other color planes are shown as shades of gray.

Select the desired plane, which varies by the selected color space. The corresponding
image and histogram should be displayed on the screen. The histogram bars are shown in
color for R, G, B, and H and as shades of gray for other color planes.

The Invert checkbox can be used at any time to invert the current image.

The Stretch checkbox can be used to the image fills the available space.

Press the Print button to see the various printing options:
The "Big Image" and "Small Image" options print the image currently
being displayed with two different sizes. The "Big Image" prints the image in
landscape orientation with the image width 80% of the page (or adjusts the image to fit
vertically). The "Small Image" prints the image in portrait orientation with the
image width 40% of the page. A time stamp is printed at the lower left of both of these
images.

The "Color Spaces" option prints a full page with an array of images (R, G, B,
Intensity, Lightness, H, S, V) in landscape orientation showing the various color planes.
The shades-of- gray images represent values from 0 to 255.
Note that for with Flower1.BMP image, the "dead" parts of the flower show up as
low (dark) saturation values.
(Note the "Hue" picture above has been changed to show the hue with color fully
saturated.)

The "Histograms" option prints a full page with an array of histograms (R, G, B,
Intensity, Black, H, S, V) in landscape orientation, along with the original RGB composite
image.
Some areas of the histograms may only print correctly on color printers.

Press the Save button at any time to save the image currently being displayed.
A Save As dialog appears so you can save the BMP file where you want.

DiscussionThe program reads an image and interactively displays RGB composite image, or R, G,
B, H, S, V, H, L, S, C, M, Y or K color planes. Note that Hue from HSV matches the Hue
from HLS, but the Saturation from HSV is slightly different from the Saturation in HLS.

The OnMouseMove events for the ImageBig area report the pixel position
(I,J) coordinates as you move the cursor, as well as a variety of color values for the
pixel. RGB coordinates are shown from 0 to 255 or 0.000 to 1.000. Hue values are shown
either from 0 to 255 or from 0 to 360 degrees. S, V, L values are shown from 0 to 255 or
0.000 to 1.000. C, M, Y, K values are shown only in the range from 0 to 255. Intensity and
Lightness are reported from 0 to 255 or from 0.000 to 1.000. Y, I, Q values are computed
from the 0.000 to 1.000 R, G, B values.

Print the image (or image plane) as "big" image in landscape orientation or
"small" image in portrait orientation. Print the array of color spaces on single
sheet. Print the array of histograms on single sheet. The histograms also show the
following statistics: minimum, maximum, mean, standard deviation (except for
"hue" where the statistics aren't meaningful).

ColorLibrary.PAS unit has various color conversion routines and support for
creating histograms. The conversions in this library are appropriate only for one-way
computations because of integer truncation in the final answer.. (For reversible
computations using floating point values, look at the RealColorLibrary.PAS file.)
StatisticsLibrary.PAS has a TDescriptiveStatistics class for
calculating, min, max, mean and standard deviation of a series of numbers.

Images processed by ShowImage are assumed to have a 4:3 aspect
ratio, e.g, 640 x 480. Color Space images may be stretched to fit if they have a different
aspect ratio.

For GIF support you will need a GIF component such as TGIFImage from Anders
Melander (or another source). Change the conditional compilation value from NOGIF to GIF and
recompile once TGIFImage is installed. (You are responsible for any licensing
with Unisys.) The FormCreate method updates the OpenPictureDialog's
filter to add GIF to the "all" group, as well as a separate GIF selection.

Images that are not 24-bits/pixel bitmaps are forced to be pf24bitTBitmaps
so they can be processed by this program.

To count the colors in a 24-bits/pixel bitmap, use a 2D array of TBits
objects. When a (R,G) combination occurs for the first time, create an array of 256
bits in the blue dimension. Set bits for each (R,G,B) combination and then count the
number set. For most images this is a fairly sparse array, but even with a
completely filled-in 3D array of bits, this process is fairly fast. See the CountColors
function in the ImageProcessingPrimitives.PAS unit.

The Windows API calls GetCValue, GetMValue, GetYValue, GetKValue
do not appear to work and were replaced with routines based on routines in Foley
and Van Dam's computer graphcis textbook. (10 Oct 2001)

ConclusionsThe ShowImage program can be used to quickly analyze a large number of
images, including various colors planes. The histograms can be used to analyze the
contents of an image.

To avoid D4 compiler warnings with this program, the D3 code was modified for D3/D4
compatibility:

In the call to the GetDIBSizes API call, declaration of the HeaderSize
and ImageSize parameters were changed from a generic Integer to a DWORD.

To avoid a runtime error when viewing the HSV histograms:

In the RGBToHSV routine in the ImageProcessingLibrary, three
occurrences of Byte differences had to be typecast to signed Integers, e.g.,

H := (60*Integer(rgbtGreen-rgbtBlue)) DIV Delta

instead of only

H := (60*(rgbtGreen-rgbtBlue)) DIV Delta

See "Caution" Note in Section B-1 of the Delphi Math Info and Links page for
information about these arithmetic changes introduced in Delphi 4. One newsgroup
report says this problem was "fixed" in Delphi 4.02.