Operations > OP_CLEAN |
OP_CLEAN: Correct Image Deficiencies Overview
The purpose of OP_CLEAN (see opcode specific data structure) is to assemble a common set of image enhancement and cleanup routines into a simple low level interface scheme for general availability. With the advent of many electronic capture devices such as digital cameras, more digital images are becoming prevalent needing digital correction or aesthetic enhancement of the image. This opcode will be a dynamic vehicle for improving images digitally. As requirements dictate, newer features will be added here to fix deficiencies typically encountered with images.
The CLEAN:OP_CLEAN section of PIC_PARM contains two parameters, subcode and method, that delineate which OP_CLEAN method to be employed. Depending on the operation, other parameters will be noted appropriately for additional control features. The following table outlines the current feature set of OP_CLEAN. Additional details can be found in the structure parameters section of this document.
Subcode |
Method |
Operation |
0 |
0 |
Remove Specks and scratches from Region Specified |
1 |
0 |
Remove streaks from image |
1 |
Do not remove RGB bright streaks | |
2 |
Remove only narrow RGB streaks | |
4 |
Remove all but wide RGB streaks | |
8 |
Leave bright narrow streaks alone | |
10 |
Combines method 2 and method 8 filters | |
12 |
Combines method 4 and method 8 filters | |
2 |
0 |
Manual setting of Brightness, Contrast, Gamma |
1 |
AutoLevels | |
2 |
AutoContrast | |
3 |
Equalize (for internal use only) | |
4 |
Load three tables | |
5 |
Load one table | |
6 |
1 |
Orientation - Flip Image |
2 |
Rotation Right 90 degrees | |
3 |
Rotate Right 90 degrees and flip | |
4 |
Rotate Right 180 degrees | |
5 |
Rotate Right 180 degrees and flip (Mirror) | |
6 |
Rotate Right 270 degrees | |
7 |
Rotate Right 270 degrees and flip | |
8 |
0 |
De-skew Image |
16 |
0 |
Precise Region Red Eye Removal |
1 |
Imprecise Region Red Eye Removal | |
2 |
Imprecise Region Red Eye Removal on Rudy Face | |
17 |
0 |
Rectangle List Red Eyes Removal |
18 |
0 |
Automatic Red Eyes Detection and Removal |
32 |
1 |
Sharpen Filter 1 |
2 |
Sharpen Filter 2 | |
3 |
Sharpen Filter 3 | |
8 |
Unsharp Mask Filter 1 | |
9 |
Unsharp Mask Filter 2 | |
10 |
Unsharp Mask Filter 3 | |
16 |
Noise Reduction Filter 1 | |
17 |
Noise Reduction Filter 2 | |
18 |
Noise Reduction Filter 3 | |
19 |
Noise Reduction Filter 4 |
Removes specks and scratches within 24 bit RGB data images. The data image area to be corrected must be fully contained in the Put Queue prior to REQ_EXEC.
Both the offsets and dimensions must specify an area fully contained within the data image or an ERR_BAD_PARAMETER_VALUE error status will be returned. Setting the Q_REVERSE flag in the PUT Qflags parameter indicates that the image is bottom up and the coordinates offsets will be applied accordingly.
The De-streak procedure removes vertical streaks from images. Typically such streaks occur when images are scanned from dirty or debris contaminated scanners. The operation works on the full 24 bit RGB image in the GET Queue memory with modified results placed in the PUT Queue.
The BCG Enhancement by Histogram Modification subcode provides a mechanism for adjusting the Brightness, Contrast and Gamma of an 8 or 24 bit image, in one of three ways: manually, automatically, or user-supplied lookup table(s). In manual mode (Method=0), the user can vary any one or all of the parameters from its default neutral value. The automatic modes are AutoLevels (Method=1) and AutoContrast (Method=2). Or the user can supply a single table (Method=4) or three tables, one per component, (Method=5) to be used. Modifications are made to the colortable of 8bpp color images or to the pixels themselves for 24bpp images and 8bpp grayscale images.
This operation is performed on a subrectangle of the image if F_Crop is set in PIC_PARM.Flags and the PIC_PARM fields CropXoff, CropYoff, CropWidth and CropHeight are set. The entire image is analyzed in the automatic modes. Only the selected region is modified and output to the Put Queue.
The user requests that the lookup tables generated and used by Methods 0, 1, 2 to change the pixels be returned by OP_CLEAN by setting LookupTables to point to a block of memory of sufficient size to hold the table(s). Set LookupTablesSize to the size in bytes of the allocated memory; OP_CLEAN uses this value to verify there is sufficient memory.
The user supplies previously-returned table(s) to OP_CLEAN by setting Method to 4 or 5, setting LookupTables to point to the table(s), and setting LookupTablesSize appropriately.
Images can be rotated and flipped. The image needs to be placed in the Get Queue prior to REQ_EXEC. Subcode 6 supports streaming input, 1, 4, 8, 16 (RGB555 and RGB565), 24 and 32 bits-per-pixel. Also 9 - 16 bits-per-pixel grayscale images if biCompression is set to BI_GRAY.
The De-skew procedure allows the user to straighten (i.e. rotate) a skewed 24 bit RGB image with anti-aliasing being applied. The user may either control the degree of rotation explicitly or allow OP_CLEAN to make the correction as best can be determined. The angle of rotation permissible is 45 degrees in 10ths of a degree increment. A consequence of de-skewing an image is that the output image size will change.
The Red Eye Removal method works at reducing the red color from flashes from either 24 bit RGB or color JPEG data. The user can select either an imprecise general area where the red eye correction is needed and let the OP_CLEAN procedure automatically locate and correct the red eye; or specify a precise area for exact control. For RGB data, the image area of interest must be placed in the Put Queue entirely prior to REQ_EXEC. For normal JPEG data, the GET Queue is used for input and the corrected data is placed in the PUT Queue as expected.
The Automatic Red Eyes Detection and Removal method tries to detect and correct the red color in eyes resulting from camera flashes. The input is 24 bit RGB data. You can select a subrectangle of the image where the red eye detection and correction is needed and then the OP_CLEAN procedure automatically locates and corrects any red eyes within that area only, otherwise the red eyes are located and corrected in the entire image. The RGB data must be placed in the Put Queue entirely prior to REQ_EXEC.
Each returned REDEYE_RECTANGLE includes the image pixel coordinates of the subrectangle containing a detected red eye along with an OP_CLEAN confidence factor from 40 to 99 indicating approximately how confident OP_CLEAN is about its detection of that red eye.
The Rectangle List Red Eyes Removal method tries to reduce the red color from camera flashes in a list of image subrectangles. The input is 24 bit RGB data. The main purpose of this subcode operation is to allow you to restore the original image data after Automatic Red Eyes Detection and Removal (Subcode 18) and then re-correct the red eyes in the RedeyeRectangleList as returned from Subcode 18, but after having deleted rectangles (or modified or inserted rectangles) based on the detection confidence value or based on interaction with your user. The RGB data must be placed in the Put Queue entirely prior to REQ_EXEC.
Sharpen, Unsharp Mask and the Noise Filters all use a 3 x 3 Convolution matrix with appropriate coefficients to provide the desired effect. Sharpen Filters are provided to help contrast edges within an image. Several filters of each kind are provided giving a choice for correction depending on the severity of correction needed.
Unsharp masking is the subtraction of a low-resolution image from a normal-resolution image (with suitable weighing factors) to create a masked image. In effect this is the combining of a noise-cleaning filter with a sharpening filter
Noise filters reduce graininess and light dust like artifacts. Noise correction here is different from the speck removal option in that the noise is expected to be more uniform over the entire image and not as pronounced as a blemish or scratch in the image. Both Get and Put Queues are used for these filters.
The matrix is represented by four values A, B, C, and S in the following array:
A B A
B C B / S
A B A
and S is used to normalize the resulting value. The matrix and S make up a filter. Suppose at some point x[c,r] in an image, the pixels for three consecutive lines are represented by:
x[c-1,r-1] x[c,r-1] x[c+1,r-1]
x[c-1,r] x[c,r] x[c+1,r]
x[c-1,r+1] x[c,r+1] x[c+1,r+1]
then the new value to replace x[c,r] is
( A*x[c-1,r-1] + B*x[c,r-1] + A*x[c+1,r-1] +
B*x[c-1,r] + C*x[c,r] + B*x[c+1,r] +
A*x[c-1,r+1] + B*x[c,r+1] + A*x[c+1,r+1] ) / S
That is, each element of the matrix centered about C is multiplied by the corresponding neighbor of x[c,r] and the products are added. The resulting sum is divided by S and clipped to ensure the final value is within 0 to 255.
0 |
-1 |
0 |
|
|
|
-1 |
-1 |
-1 |
|
|
|
1 |
-2 |
1 |
|
|
-1 |
5 |
-1 |
/ |
1 |
|
-1 |
9 |
-1 |
/ |
6 |
|
-2 |
5 |
-2 |
/ |
1 |
0 |
-1 |
0 |
|
|
|
-1 |
-1 |
-1 |
|
|
|
1 |
-2 |
1 |
|
|
method = 1 method = 2 method = 3
-1 |
-1 |
-1 |
|
|
|
-2 |
-2 |
-2 |
|
|
|
1 |
-2 |
1 |
|
|
-1 |
17 |
-1 |
/ |
9 |
|
-2 |
43 |
-2 |
/ |
27 |
|
-2 |
24 |
-2 |
/ |
12 |
-1 |
-1 |
-1 |
|
|
|
-2 |
-2 |
-2 |
|
|
|
1 |
-2 |
1 |
|
|
method = 8 method =9 method = 10
1 |
1 |
1 |
|
|
|
0 |
1 |
0 |
|
|
|
1 |
1 |
1 |
|
|
|
1 |
2 |
1 |
|
|
1 |
1 |
1 |
/ |
9 |
|
1 |
2 |
1 |
/ |
6 |
|
1 |
2 |
1 |
/ |
10 |
|
2 |
4 |
2 |
/ |
16 |
1 |
1 |
1 |
|
|
|
0 |
1 |
0 |
|
|
|
1 |
1 |
1 |
|
|
|
1 |
2 |
1 |
|
|
method = 16 method = 17 method = 18 method = 19