#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"
Функции | |
l_int32 | pixColorContent (PIX *pixs, l_int32 rwhite, l_int32 gwhite, l_int32 bwhite, l_int32 mingray, PIX **ppixr, PIX **ppixg, PIX **ppixb) |
PIX * | pixColorMagnitude (PIX *pixs, l_int32 rwhite, l_int32 gwhite, l_int32 bwhite, l_int32 type) |
l_int32 | pixColorFraction (PIX *pixs, l_int32 darkthresh, l_int32 lightthresh, l_int32 diffthresh, l_int32 factor, l_float32 *ppixfract, l_float32 *pcolorfract) |
l_int32 | pixNumSignificantGrayColors (PIX *pixs, l_int32 darkthresh, l_int32 lightthresh, l_float32 minfract, l_int32 factor, l_int32 *pncolors) |
l_int32 | pixColorsForQuantization (PIX *pixs, l_int32 thresh, l_int32 *pncolors, l_int32 *piscolor, l_int32 debug) |
l_int32 | pixNumColors (PIX *pixs, l_int32 factor, l_int32 *pncolors) |
l_int32 pixColorContent | ( | PIX * | pixs, | |
l_int32 | rwhite, | |||
l_int32 | gwhite, | |||
l_int32 | bwhite, | |||
l_int32 | mingray, | |||
PIX ** | ppixr, | |||
PIX ** | ppixg, | |||
PIX ** | ppixb | |||
) |
Input: pixs (32 bpp rgb or 8 bpp colormapped) rwhite, gwhite, bwhite (color value associated with white point) mingray (min gray value for which color is measured) &pixr (<optional return>=""> 8 bpp red 'content') &pixg (<optional return>=""> 8 bpp green 'content') &pixb (<optional return>=""> 8 bpp blue 'content') Return: 0 if OK, 1 on error
Notes: (1) This returns the color content in each component, which is a measure of the deviation from gray, and is defined as the difference between the component and the average of the other two components. See the discussion at the top of this file. (2) The three numbers (rwhite, gwhite and bwhite) can be thought of as the values in the image corresponding to white. They are used to compensate for an unbalanced color white point. They must either be all 0 or all non-zero. To turn this off, set them all to 0. (3) If the maximum component after white point correction, max(r,g,b), is less than mingray, all color components for that pixel are set to zero. Use mingray = 0 to turn off this filtering of dark pixels. (4) Therefore, use 0 for all four input parameters if the color magnitude is to be calculated without either white balance correction or dark filtering.
l_int32 pixColorFraction | ( | PIX * | pixs, | |
l_int32 | darkthresh, | |||
l_int32 | lightthresh, | |||
l_int32 | diffthresh, | |||
l_int32 | factor, | |||
l_float32 * | ppixfract, | |||
l_float32 * | pcolorfract | |||
) |
Input: pixs (32 bpp rgb) darkthresh (dark threshold for minimum of average value to be considered in the statistics; typ. 20) lightthresh (threshold near white, above which the pixel is not considered in the statistics; typ. 248) diffthresh (thresh for the maximum difference from the average of component values) factor (subsampling factor) &pixfract (<return> fraction of pixels in intermediate brightness range that were considered for color content) &colorfract (<return> fraction of pixels that meet the criterion for sufficient color; 0.0 on error) Return: 0 if OK, 1 on error
Notes: (1) This function is asking the question: to what extent does the image appear to have color? The amount of color a pixel appears to have depends on both the deviation of the individual components from their average and on the average intensity itself. For example, the color will be much more obvious with a small deviation from white than the same deviation from black. (2) Any pixel that meets these three tests is considered a colorful pixel: (a) the average of components must equal or exceed (b) the average of components must not exceed (c) at least one component must differ from the average by at least (3) The dark pixels are removed from consideration because they don't appear to have color. (4) The very lightest pixels are removed because if an image has a lot of "white", the color fraction will be artificially low, even if all the other pixels are colorful. (5) If pixfract is very small, there are few pixels that are neither black nor white. If colorfract is very small, the pixels that are neither black nor white have very little color content. The product 'pixfract * colorfract' gives the fraction of pixels with significant color content. (6) One use of this function is as a preprocessing step for median cut quantization (colorquant2.c), which does a very poor job splitting the color space into rectangular volume elements when all the pixels are near the diagonal of the color cube. For octree quantization of an image with only gray values, the 2^(level) octcubes on the diagonal are the only ones that can be occupied.
Input: pixs (32 bpp rgb or 8 bpp colormapped) rwhite, gwhite, bwhite (color value associated with white point) type (chooses the method for calculating the color magnitude: L_MAX_DIFF_FROM_AVERAGE_2, MAX_MIN_DIFF_FROM_2) Return: pixd (8 bpp, amount of color in each source pixel), or NULL on error
Notes: (1) For an RGB image, a gray pixel is one where all three components are equal. We define the amount of color in an RGB pixel by considering the absolute value of the differences between the components, of which there are three. Consider the two largest of these differences. The pixel component in common to these two differences is the color farthest from the other two. The color magnitude in an RGB pixel can be taken as: * the average of these two differences; i.e., the average distance from the two components that are nearest to each other to the third component, or * the minimum value of these two differences; i.e., the maximum over all components of the minimum distance from that component to the other two components. (2) As an example, suppose that R and G are the closest in magnitude. Then the color is determined as either: * the average distance of B from these two; namely, (|B - R| + |B - G|) / 2, which can also be found from |B - (R + G) / 2|, or * the minimum distance of B from these two; namely, min(|B - R|, |B - G|). (3) The three numbers (rwhite, gwhite and bwhite) can be thought of as the values in the image corresponding to white. They are used to compensate for an unbalanced color white point. They must either be all 0 or all non-zero. To turn this off, set them all to 0. (4) We allow the following methods for choosing the color magnitude from the three components: * L_MAX_DIFF_FROM_AVERAGE_2 * L_MAX_MIN_DIFF_FROM_2 These are described above in (1) and (2), as well as at the top of this file.
l_int32 pixColorsForQuantization | ( | PIX * | pixs, | |
l_int32 | thresh, | |||
l_int32 * | pncolors, | |||
l_int32 * | piscolor, | |||
l_int32 | debug | |||
) |
pixColorsForQuantization() Input: pixs (8 bpp gray or 32 bpp rgb; with or without colormap) thresh (binary threshold on edge gradient; 0 for default) &ncolors (<return> the number of colors found) &iscolor (<optional return>=""> 1 if significant color is found; 0 otherwise. If pixs is 8 bpp, this is 0) debug (1 to output masked image that is tested for colors; 0 otherwise) Return: 0 if OK, 1 on error.
Notes: (1) Grayscale and color quantization is often useful to achieve highly compressed images with little visible distortion. However, gray or color washes (regions of low gradient) can defeat this approach to high compression. How can one determine if an image is expected to compress well using gray or color quantization? We use the fact that
pixNumColors() Input: pixs (2, 4, 8, 32 bpp) factor (subsampling factor; integer) &ncolors (<return> the number of colors found, or 0 if there are more than 256) Return: 0 if OK, 1 on error.
Notes: (1) This returns the actual number of colors found in the image, even if there is a colormap. If == 1 and the number of colors differs from the number of entries in the colormap, a warning is issued. (2) Use == 1 to find the actual number of colors. Use > 1 to quickly find the approximate number of colors. (3) For d = 2, 4 or 8 bpp grayscale, this returns the number of colors found in the image in 'ncolors'. (4) For d = 32 bpp (rgb), if the number of colors is greater than 256, this returns 0 in 'ncolors'.
l_int32 pixNumSignificantGrayColors | ( | PIX * | pixs, | |
l_int32 | darkthresh, | |||
l_int32 | lightthresh, | |||
l_float32 | minfract, | |||
l_int32 | factor, | |||
l_int32 * | pncolors | |||
) |
Input: pixs (8 bpp gray) darkthresh (dark threshold for minimum intensity to be considered; typ. 20) lightthresh (threshold near white, for maximum intensity to be considered; typ. 236) minfract (minimum fraction of all pixels to include a level as significant; typ. 0.0001) factor (subsample factor; integer >= 1) &ncolors (<return> number of significant colors; 0 on error) Return: 0 if OK, 1 on error
Notes: (1) This function is asking the question: how many perceptually significant gray color levels is in this pix? A color level must meet 3 criteria to be significant: