| Pixel Profile | Lab Report | |||
|
Chinese Translation by Hector Xiang |
||||
Purpose
The purpose of this project is to display the pixel profile
-- a graph of pixel values -- from two arbitrary points on an image. The pixel
profile graph can be of Red, Green, Blue values, or derived values Intensity, Hue,
Saturation and Value. A pixel profile may be useful in the analysis of an image.
For example, the pixel profile on the "Maize" image will be used to count
the kernels of corn.
Materials and Equipment
Software Requirements
Windows 95/98
Delphi 3 or 4 (to recompile)
PixelProfile.EXE
GIF Support: Requires Anders Melander's TGIFImage and a "GIF" conditional to be set before compilation.Hardware Requirements
Super VGA display with 800-by-600 screen in high/true color display mode
Procedure
![]()
![]()
Discussion
The data or graph provided by the Pixel Profile can be useful in analyzing an
image. For example, the number of kernels of corn (maize) in the image above can be
determined by analyzing the Pixel Profile.
The data from the Pixel Profile shown above can be cut and paste into another application, or even saved to an ASCII text file using an editor.
This data can be imported into an Excel Spreadsheet. The following shows the analysis of the the "Red" data profile:
![]()
The Index and Red columns are from the Data Tab Sheet shown above. The Smooth column is the average Red[index-2], Red[index-1], Red[index], Red[index+1], Red[index+2], which is used to make the technique less sensitive to "noise" in the data. The Slope column is (Delta Y) / (Delta X), which in this case is simply Smooth[index] - Smooth[index-1]. The Sign column is the sign (-1, 0, +1) of the Slope column. A peak is near the point where the slope changes from increasing (+1) to decreasing (-1). The "1 -> -1" column identifies when a peak occurs. In this image these "peaks" correspond to each kernel in the maize corn.
This is summarized in the following graph:
![]()
All 15 peaks (i.e., kernels of corn) in the data were found using this technique.
Notes about the program:
The FormCreate includes the assignment, OpenPictureDialog.Filter := GraphicFilter(TGraphic), to make sure all registered graphic file formats (especially, JPG and GIF) can be read using the TOpenPictureDialog.
The polymorphic TPicture was used to load images into a TBitmap in ButtonLoadImageClick.
The PixelFormat is forced to pf24bit when an image is loaded.
The LineLibrary unit has a number of routines for working with lines. In particular, the NearLine function is used with the Select Tool to move a line.
During the mouse move events, the cursor movement is restricted to be within the image using the RestrictCusorToDrawingArea routine (in LineLibrary).
The routine CreateProfileLine creates the "Pixel Slice" bitmap shown on the Graphs Tab Sheet while also adding the data to the MemoData TMemo and creating the Series shown in the ChartPixelProfile TChart.
The single line of data shown while the profile line is being drawn does not create flicker in the image. However, for unexplained reason, having additional TLabel objects on the Tab Sheet resulted in undesirable flicker while the profile line is being drawn. Therefore, RGB, HSV and Intensity are not displayed while drawing the profile line. Also to eliminate flicker, the size of the TImage object was shrunk, when necessary, so the TBitmap and the TImage were the same size. (This also prevented a range check error in the CreateProfileLine routine.)
See pixel profiles of a USAF 1951 Test Target, which is a way to quantify resolution of a system.
Example of using Pixel Profile as part of measuring modulation transfer function in article about understanding image sharpness.
Conclusions
The Pixel Profile is a useful tool to analyze color images.
Keywords
TChart, MouseDown/MouseMove/MouseUp, XOR Rubberband, Scanline, RGB, HSV, RGB/HSV
Conversion, Intensity, TRGBTripleArray, TPicture, GraphicFilter,
RestrictCursorToDrawingArea, RemoveCursorRestrictions, NearLine function
Download
Delphi 3/4 Source and EXE (264 KB): PixelProfile.ZIP
Special version for display of 1024-by-1024 images (Delphi 7 with Source): PixelProfile1024.ZIP [30 June 2003]
Version of PixelProfile by MSDS to paste results to Excel spreadsheet (Sept 2004)
Updated 12 Feb 2005
since 21 Mar 1999