Файл src/compare.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "allheaders.h"

Функции

l_int32 pixEqual (PIX *pix1, PIX *pix2, l_int32 *psame)
l_int32 pixEqualWithCmap (PIX *pix1, PIX *pix2, l_int32 *psame)
l_int32 pixUsesCmapColor (PIX *pixs, l_int32 *pcolor)
l_int32 pixCorrelationBinary (PIX *pix1, PIX *pix2, l_float32 *pval)
l_int32 pixCompareBinary (PIX *pix1, PIX *pix2, l_int32 comptype, l_float32 *pfract, PIX **ppixdiff)
l_int32 pixCompareGrayOrRGB (PIX *pix1, PIX *pix2, l_int32 comptype, l_int32 plottype, l_int32 *psame, l_float32 *pdiff, l_float32 *prmsdiff, PIX **ppixdiff)
l_int32 pixCompareGray (PIX *pix1, PIX *pix2, l_int32 comptype, l_int32 plottype, l_int32 *psame, l_float32 *pdiff, l_float32 *prmsdiff, PIX **ppixdiff)
l_int32 pixCompareRGB (PIX *pix1, PIX *pix2, l_int32 comptype, l_int32 plottype, l_int32 *psame, l_float32 *pdiff, l_float32 *prmsdiff, PIX **ppixdiff)
l_int32 pixCompareTiled (PIX *pix1, PIX *pix2, l_int32 sx, l_int32 sy, l_int32 type, PIX **ppixdiff)
NUMApixCompareRankDifference (PIX *pix1, PIX *pix2)

Переменные

static const l_float32 TINY = 0.00001

Функции

l_int32 pixCompareBinary ( PIX pix1,
PIX pix2,
l_int32  comptype,
l_float32 pfract,
PIX **  ppixdiff 
)

pixCompareBinary()

Input: pix1 (1 bpp) pix2 (1 bpp) comptype (L_COMPARE_XOR, L_COMPARE_SUBTRACT) &fract (<return> fraction of pixels that are different) &pixdiff (<optional return>=""> pix of difference) Return: 0 if OK; 1 on error

Notes: (1) The two images are aligned at the UL corner, and do not need to be the same size. (2) If using L_COMPARE_SUBTRACT, pix2 is subtracted from pix1. (3) The total number of pixels is determined by pix1.

l_int32 pixCompareGray ( PIX pix1,
PIX pix2,
l_int32  comptype,
l_int32  plottype,
l_int32 psame,
l_float32 pdiff,
l_float32 prmsdiff,
PIX **  ppixdiff 
)

pixCompareGray()

Input: pix1 (8 or 16 bpp, not cmapped) pix2 (8 or 16 bpp, not cmapped) comptype (L_COMPARE_SUBTRACT, L_COMPARE_ABS_DIFF) plottype (gplot plot output type, or 0 for no plot) &same (<optional return>=""> 1 if pixel values are identical) &diff (<optional return>=""> average difference) &rmsdiff (<optional return>=""> rms of difference) &pixdiff (<optional return>=""> pix of difference) Return: 0 if OK; 1 on error

Notes: (1) See pixCompareGrayOrRGB() for details. (2) Use pixCompareGrayOrRGB() if the input pix are colormapped.

l_int32 pixCompareGrayOrRGB ( PIX pix1,
PIX pix2,
l_int32  comptype,
l_int32  plottype,
l_int32 psame,
l_float32 pdiff,
l_float32 prmsdiff,
PIX **  ppixdiff 
)

pixCompareGrayOrRGB()

Input: pix1 (8 or 16 bpp gray, 32 bpp rgb, or colormapped) pix2 (8 or 16 bpp gray, 32 bpp rgb, or colormapped) comptype (L_COMPARE_SUBTRACT, L_COMPARE_ABS_DIFF) plottype (gplot plot output type, or 0 for no plot) &same (<optional return>=""> 1 if pixel values are identical) &diff (<optional return>=""> average difference) &rmsdiff (<optional return>=""> rms of difference) &pixdiff (<optional return>=""> pix of difference) Return: 0 if OK; 1 on error

Notes: (1) The two images are aligned at the UL corner, and do not need to be the same size. If they are not the same size, the comparison will be made over overlapping pixels. (2) If there is a colormap, it is removed and the result is either gray or RGB depending on the colormap. (3) If RGB, each component is compared separately. (4) If type is L_COMPARE_ABS_DIFF, pix2 is subtracted from pix1 and the absolute value is taken. (5) If type is L_COMPARE_SUBTRACT, pix2 is subtracted from pix1 and the result is clipped to 0. (6) The plot output types are specified in gplot.h. Use 0 if no difference plot is to be made. (7) If the images are pixelwise identical, no difference plot is made, even if requested. The result (TRUE or FALSE) is optionally returned in the parameter 'same'. (8) The average difference (either subtracting or absolute value) is optionally returned in the parameter 'diff'. (9) The RMS difference is optionally returned in the parameter 'rmsdiff'. For RGB, we return the average of the RMS differences for each of the components.

NUMA* pixCompareRankDifference ( PIX pix1,
PIX pix2 
)

pixCompareRankDifference()

Input: pix1 (8 bpp gray or 32 bpp rgb, or colormapped) pix2 (8 bpp gray or 32 bpp rgb, or colormapped) Return: narank (numa of rank difference), or null on error

Notes: (1) This answers the question: if the pixel values in each component are compared by absolute difference, for any value of difference, what is the fraction of pixel pairs that have a difference of this magnitude or greater. For a difference of 0, the fraction is 1.0. In this sense, it is a mapping from pixel difference to rank order of difference. (2) The two images are aligned at the UL corner, and do not need to be the same size. If they are not the same size, the comparison will be made over overlapping pixels. (3) If there is a colormap, it is removed and the result is either gray or RGB depending on the colormap. (4) If RGB, pixel differences for each component are aggregated into a single histogram.

l_int32 pixCompareRGB ( PIX pix1,
PIX pix2,
l_int32  comptype,
l_int32  plottype,
l_int32 psame,
l_float32 pdiff,
l_float32 prmsdiff,
PIX **  ppixdiff 
)

pixCompareRGB()

Input: pix1 (32 bpp rgb) pix2 (32 bpp rgb) comptype (L_COMPARE_SUBTRACT, L_COMPARE_ABS_DIFF) plottype (gplot plot output type, or 0 for no plot) &same (<optional return>=""> 1 if pixel values are identical) &diff (<optional return>=""> average difference) &rmsdiff (<optional return>=""> rms of difference) &pixdiff (<optional return>=""> pix of difference) Return: 0 if OK; 1 on error

Notes: (1) See pixCompareGrayOrRGB() for details.

l_int32 pixCompareTiled ( PIX pix1,
PIX pix2,
l_int32  sx,
l_int32  sy,
l_int32  type,
PIX **  ppixdiff 
)

pixCompareTiled()

Input: pix1 (8 bpp or 32 bpp rgb) pix2 (8 bpp 32 bpp rgb) sx, sy (tile size; must be > 1) type (L_MEAN_ABSVAL or L_ROOT_MEAN_SQUARE) &pixdiff (<return> pix of difference) Return: 0 if OK; 1 on error

Notes: (1) With L_MEAN_ABSVAL, we compute for each tile the average abs value of the pixel component difference between the two (aligned) images. With L_ROOT_MEAN_SQUARE, we compute instead the rms difference over all components. (2) The two input pix must be the same depth. Comparison is made using UL corner alignment. (3) For 32 bpp, the distance between corresponding tiles is found by averaging the measured difference over all three components of each pixel in the tile. (4) The result, pixdiff, contains one pixel for each source tile.

l_int32 pixCorrelationBinary ( PIX pix1,
PIX pix2,
l_float32 pval 
)

pixCorrelationBinary()

Input: pix1 (1 bpp) pix2 (1 bpp) &val (<return> correlation) Return: 0 if OK; 1 on error

Notes: (1) The correlation is a number between 0.0 and 1.0, based on foreground similarity: (|1 AND 2|)**2 correlation = -------------- |1| * |2| where |x| is the count of foreground pixels in image x. If the images are identical, this is 1.0. If they have no fg pixels in common, this is 0.0. If one or both images have no fg pixels, the correlation is 0.0. (2) Typically the two images are of equal size, but this is not enforced. Instead, the UL corners are be aligned.

l_int32 pixEqual ( PIX pix1,
PIX pix2,
l_int32 psame 
)

pixEqual()

Input: pix1 pix2 &same (<return> 1 if same; 0 if different) Return: 0 if OK; 1 on error

Notes: (1) Equality is defined as having the same pixel values for each respective image pixel. (2) This works on two pix of any depth. If one or both pix have a colormap, the depths can be different and the two pix can still be equal. (3) If both pix have colormaps and the depths are equal, use the pixEqualWithCmap() function, which does a fast comparison if the colormaps are identical and a relatively slow comparison otherwise. (4) In all other cases, any existing colormaps must first be removed before doing pixel comparison. After the colormaps are removed, the resulting two images must have the same depth. The "lowest common denominator" is RGB, but this is only chosen when necessary, or when both have colormaps but different depths. (5) For 32 bpp, ignore the bits in the 4th byte (the 'A' byte of the RGBA pixel) (6) For images without colormaps that are not 32 bpp, all bits in the image part of the data array must be identical.

l_int32 pixEqualWithCmap ( PIX pix1,
PIX pix2,
l_int32 psame 
)

pixEqualWithCmap()

Input: pix1 pix2 &same Return: 0 if OK, 1 on error

Notes: (1) This returns same = TRUE if the images have identical content. (2) Both pix must have a colormap, and be of equal size and depth. If these conditions are not satisfied, it is not an error; the returned result is same = FALSE. (3) We then check whether the colormaps are the same; if so, the comparison proceeds 32 bits at a time. (4) If the colormaps are different, the comparison is done by slow brute force.

l_int32 pixUsesCmapColor ( PIX pixs,
l_int32 pcolor 
)

pixUsesCmapColor()

Input: pixs &color (<return>) Return: 0 if OK, 1 on error

Notes: (1) This returns color = TRUE if three things are obtained: (a) the pix has a colormap (b) the colormap has at least one color entry (c) a color entry is actually used (2) It is used in pixEqual() for comparing two images, in a situation where it is required to know if the colormap has color entries that are actually used in the image.


Переменные

const l_float32 TINY = 0.00001 [static]


Документация по Leptonica. Последние изменения: Fri Aug 7 20:31:35 2009. Создано системой  doxygen 1.5.9