|Show RGB, HSV, HLS, or CMYK Color Coordinates, Planes and Histograms|
|Shown above is the Hue space (of HSV color space) with fully saturated colors.|
The 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
Delphi 3 or 4 (to recompile)
BMP, JPG, ICO, EMF, WMF file (GIFs can be used if you have a TGIFImage component. See below.)
1024 x 768 display in high color or true color mode
The 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
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 pf24bit TBitmaps 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)
The 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.
HLS (Hue-Lightness-Saturation )
CMYK (Cyan-Magenta-Yellow-Black), Intensity, Lightness
YIQ (intensity, chromaticity -- "Y" is the part of a color TV signal displayed on black-and-white sets)
BMP, JPG, ICO, EMF, WMF, GIF
TBits (used in CountColors)
OnMouseMove, Histogram (a frequency distribution), Color Plane, TDescriptiveStatistics, GetRValue, GetGValue, GetBValue, GetCValue, GetMValue, GetYValue, GetKValue, TIniFile, TColor
Delphi 3/4/5 Source and EXE (227 KB): ShowImage.ZIP
24-bit color BMP test image:
Parrots.ZIP (200 KB)
8-bit color BMP test image:
Deer.ZIP (28 KB) [note the "sparse" histogram with a 256-color image]
The October/November 1998 updates added the following features:
The January 2000 update:
Delphi 4 Conversion Notes
To avoid D4 compiler warnings with this program, the D3 code was modified for D3/D4 compatibility:
To avoid a runtime error when viewing the HSV histograms:
The Delphi 4 EXE is larger than the Delphi 3 EXE:
Delphi 3 EXE: 382 KB
Delphi 4 EXE: 478 KB
Delphi 5 EXE: 489 KB
Updated 26 Feb 2005
since 1 Nov 1998