本文整理汇总了C++中pixcmapGetCount函数的典型用法代码示例。如果您正苦于以下问题:C++ pixcmapGetCount函数的具体用法?C++ pixcmapGetCount怎么用?C++ pixcmapGetCount使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pixcmapGetCount函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pixcmapAddNewColor
/*!
* pixcmapAddNewColor()
*
* Input: cmap
* rval, gval, bval (colormap entry to be added; each number
* is in range [0, ... 255])
* &index (<return> index of color)
* Return: 0 if OK, 1 on error; 2 if unable to add color
*
* Notes:
* (1) This only adds color if not already there.
* (2) This returns the index of the new (or existing) color.
* (3) Returns 2 with a warning if unable to add this color;
* the caller should check the return value.
*/
l_int32
pixcmapAddNewColor(PIXCMAP *cmap,
l_int32 rval,
l_int32 gval,
l_int32 bval,
l_int32 *pindex)
{
PROCNAME("pixcmapAddNewColor");
if (!pindex)
return ERROR_INT("&index not defined", procName, 1);
*pindex = 0;
if (!cmap)
return ERROR_INT("cmap not defined", procName, 1);
/* Check if the color is already present. */
if (!pixcmapGetIndex(cmap, rval, gval, bval, pindex)) /* found */
return 0;
/* We need to add the color. Is there room? */
if (cmap->n >= cmap->nalloc) {
L_WARNING("no free color entries", procName);
return 2;
}
/* There's room. Add it. */
pixcmapAddColor(cmap, rval, gval, bval);
*pindex = pixcmapGetCount(cmap) - 1;
return 0;
}
示例2: pixcmapShiftIntensity
/*!
* pixcmapShiftIntensity()
*
* Input: colormap
* fraction (between -1.0 and +1.0)
* Return: 0 if OK; 1 on error
*
* Notes:
* - in-place transform
* - This does a proportional shift of the intensity for each color.
* - If fraction < 0.0, it moves all colors towards (0,0,0).
* This darkens the image.
* - If fraction > 0.0, it moves all colors towards (255,255,255)
* This fades the image.
* - The equivalent transform can be accomplished with pixcmapGammaTRC(),
* but it is considerably more difficult (see numaGammaTRC()).
*/
l_int32
pixcmapShiftIntensity(PIXCMAP *cmap,
l_float32 fraction)
{
l_int32 i, ncolors, rval, gval, bval;
PROCNAME("pixcmapShiftIntensity");
if (!cmap)
return ERROR_INT("cmap not defined", procName, 1);
if (fraction < -1.0 || fraction > 1.0)
return ERROR_INT("fraction not in [-1.0, 1.0]", procName, 1);
ncolors = pixcmapGetCount(cmap);
for (i = 0; i < ncolors; i++) {
pixcmapGetColor(cmap, i, &rval, &gval, &bval);
if (fraction < 0.0)
pixcmapResetColor(cmap, i,
(l_int32)((1.0 + fraction) * rval),
(l_int32)((1.0 + fraction) * gval),
(l_int32)((1.0 + fraction) * bval));
else
pixcmapResetColor(cmap, i,
rval + (l_int32)(fraction * (255 - rval)),
gval + (l_int32)(fraction * (255 - gval)),
bval + (l_int32)(fraction * (255 - bval)));
}
return 0;
}
示例3: pixcmapHasColor
/*!
* pixcmapHasColor()
*
* Input: cmap
* &color (<return> TRUE if cmap has color; FALSE otherwise)
* Return: 0 if OK, 1 on error
*/
LEPTONICA_EXPORT l_int32
pixcmapHasColor(PIXCMAP *cmap,
l_int32 *pcolor)
{
l_int32 n, i;
l_int32 *rmap, *gmap, *bmap;
PROCNAME("pixcmapHasColor");
if (!pcolor)
return ERROR_INT("&color not defined", procName, 1);
*pcolor = FALSE;
if (!cmap)
return ERROR_INT("cmap not defined", procName, 1);
if (pixcmapToArrays(cmap, &rmap, &gmap, &bmap))
return ERROR_INT("colormap arrays not made", procName, 1);
n = pixcmapGetCount(cmap);
for (i = 0; i < n; i++) {
if ((rmap[i] != gmap[i]) || (rmap[i] != bmap[i])) {
*pcolor = TRUE;
break;
}
}
FREE(rmap);
FREE(gmap);
FREE(bmap);
return 0;
}
示例4: pixcmapGetRankIntensity
/*!
* pixcmapGetRankIntensity()
*
* Input: cmap
* rankval (0.0 for darkest, 1.0 for lightest color)
* &index (<return> the index into the colormap that
* corresponds to the rank intensity color)
* Return: 0 if OK, 1 on error
*/
l_int32
pixcmapGetRankIntensity(PIXCMAP *cmap,
l_float32 rankval,
l_int32 *pindex)
{
l_int32 n, i, rval, gval, bval, rankindex;
NUMA *na, *nasort;
PROCNAME("pixcmapGetRankIntensity");
if (!pindex)
return ERROR_INT("&index not defined", procName, 1);
*pindex = 0;
if (!cmap)
return ERROR_INT("cmap not defined", procName, 1);
if (rankval < 0.0 || rankval > 1.0)
return ERROR_INT("rankval not in [0.0 ... 1.0]", procName, 1);
n = pixcmapGetCount(cmap);
na = numaCreate(n);
for (i = 0; i < n; i++) {
pixcmapGetColor(cmap, i, &rval, &gval, &bval);
numaAddNumber(na, rval + gval + bval);
}
nasort = numaGetSortIndex(na, L_SORT_INCREASING);
rankindex = (l_int32)(rankval * (n - 1) + 0.5);
numaGetIValue(nasort, rankindex, pindex);
numaDestroy(&na);
numaDestroy(&nasort);
return 0;
}
示例5: pixcmapContrastTRC
/*!
* pixcmapContrastTRC()
*
* Input: colormap
* factor (generally between 0.0 (no enhancement)
* and 1.0, but can be larger than 1.0)
* Return: 0 if OK; 1 on error
*
* Notes:
* - in-place transform
* - see pixContrastTRC() and numaContrastTRC() in enhance.c for
* description and use of transform
*/
l_int32
pixcmapContrastTRC(PIXCMAP *cmap,
l_float32 factor)
{
l_int32 i, ncolors, rval, gval, bval, trval, tgval, tbval;
NUMA *nac;
PROCNAME("pixcmapContrastTRC");
if (!cmap)
return ERROR_INT("cmap not defined", procName, 1);
if (factor < 0.0) {
L_WARNING("factor must be >= 0.0; setting to 0.0", procName);
factor = 0.0;
}
if ((nac = numaContrastTRC(factor)) == NULL)
return ERROR_INT("nac not made", procName, 1);
ncolors = pixcmapGetCount(cmap);
for (i = 0; i < ncolors; i++) {
pixcmapGetColor(cmap, i, &rval, &gval, &bval);
numaGetIValue(nac, rval, &trval);
numaGetIValue(nac, gval, &tgval);
numaGetIValue(nac, bval, &tbval);
pixcmapResetColor(cmap, i, trval, tgval, tbval);
}
numaDestroy(&nac);
return 0;
}
示例6: DisplayMapHistogram
static void
DisplayMapHistogram(L_AMAP *m,
PIXCMAP *cmap,
const char *rootname)
{
char buf[128];
l_int32 i, n, ival;
l_uint32 val32;
NUMA *na;
RB_TYPE key;
RB_TYPE *pval;
n = pixcmapGetCount(cmap);
na = numaCreate(n);
for (i = 0; i < n; i++) {
pixcmapGetColor32(cmap, i, &val32);
key.utype = val32;
pval = l_amapFind(m, key);
if (pval) {
ival = pval->itype;
numaAddNumber(na, ival);
}
}
gplotSimple1(na, GPLOT_PNG, rootname, NULL);
snprintf(buf, sizeof(buf), "%s.png", rootname);
l_fileDisplay(buf, 700, 0, 1.0);
numaDestroy(&na);
return;
}
示例7: pixcmapToRGBTable
/*!
* pixcmapToRGBTable()
*
* Input: colormap
* &tab (<return> table of rgba values for the colormap)
* &ncolors (<optional return> size of table)
* Return: 0 if OK; 1 on error
*/
l_int32
pixcmapToRGBTable(PIXCMAP *cmap,
l_uint32 **ptab,
l_int32 *pncolors)
{
l_int32 i, ncolors, rval, gval, bval;
l_uint32 *tab;
PROCNAME("pixcmapToRGBTable");
if (!ptab)
return ERROR_INT("&tab not defined", procName, 1);
*ptab = NULL;
if (!cmap)
return ERROR_INT("cmap not defined", procName, 1);
ncolors = pixcmapGetCount(cmap);
if (pncolors)
*pncolors = ncolors;
if ((tab = (l_uint32 *)CALLOC(ncolors, sizeof(l_uint32))) == NULL)
return ERROR_INT("tab not made", procName, 1);
*ptab = tab;
for (i = 0; i < ncolors; i++) {
pixcmapGetColor(cmap, i, &rval, &gval, &bval);
composeRGBPixel(rval, gval, bval, &tab[i]);
}
/* for (i = 0; i < ncolors; i++)
fprintf(stderr, "Color[%d] = %x\n", i, tab[i]); */
return 0;
}
示例8: DisplayMapHistogram
static void
DisplayMapHistogram(L_AMAP *m,
PIXCMAP *cmap,
const char *rootname)
{
l_int32 i, n, ival;
l_uint32 val32;
NUMA *na;
RB_TYPE key;
RB_TYPE *pval;
n = pixcmapGetCount(cmap);
na = numaCreate(n);
for (i = 0; i < n; i++) {
pixcmapGetColor32(cmap, i, &val32);
key.utype = val32;
pval = l_amapFind(m, key);
if (pval) {
ival = pval->itype;
numaAddNumber(na, ival);
}
}
/* numaWrite("/tmp/lept/map/map.na", na); */
gplotSimple1(na, GPLOT_X11, rootname, NULL);
numaDestroy(&na);
return;
}
示例9: pixcmapGetIndex
/*!
* pixcmapGetIndex()
*
* Input: cmap
* rval, gval, bval (colormap colors to search for; each number
* is in range [0, ... 255])
* &index (<return>)
* Return: 0 if found, 1 if not found (caller must check)
*/
l_int32
pixcmapGetIndex(PIXCMAP *cmap,
l_int32 rval,
l_int32 gval,
l_int32 bval,
l_int32 *pindex)
{
l_int32 n, i;
RGBA_QUAD *cta;
PROCNAME("pixcmapGetIndex");
if (!pindex)
return ERROR_INT("&index not defined", procName, 1);
*pindex = 0;
if (!cmap)
return ERROR_INT("cmap not defined", procName, 1);
n = pixcmapGetCount(cmap);
cta = (RGBA_QUAD *)cmap->array;
for (i = 0; i < n; i++) {
if (rval == cta[i].red && gval == cta[i].green && bval == cta[i].blue) {
*pindex = i;
return 0;
}
}
return 1;
}
示例10: pixcmapCountGrayColors
/*!
* pixcmapCountGrayColors()
*
* Input: cmap
* &ngray (<return> number of gray colors)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) This counts the unique gray colors, including black and white.
*/
l_int32
pixcmapCountGrayColors(PIXCMAP *cmap,
l_int32 *pngray)
{
l_int32 n, i, rval, gval, bval, count;
l_int32 *array;
PROCNAME("pixcmapCountGrayColors");
if (!pngray)
return ERROR_INT("&ngray not defined", procName, 1);
*pngray = 0;
if (!cmap)
return ERROR_INT("cmap not defined", procName, 1);
array = (l_int32 *)CALLOC(256, sizeof(l_int32));
n = pixcmapGetCount(cmap);
count = 0;
for (i = 0; i < n; i++) {
pixcmapGetColor(cmap, i, &rval, &gval, &bval);
if ((rval == gval) && (rval == bval) && (array[rval] == 0)) {
array[rval] = 1;
count++;
}
}
FREE(array);
*pngray = count;
return 0;
}
示例11: CmapEqual
void
CmapEqual(PIXCMAP *cmap1, PIXCMAP *cmap2, l_int32 *pequal)
{
l_int32 n1, n2, i, rval1, gval1, bval1, aval1, rval2, gval2, bval2, aval2;
*pequal = FALSE;
n1 = pixcmapGetCount(cmap1);
n2 = pixcmapGetCount(cmap1);
if (n1 != n2) return;
for (i = 0; i < n1; i++) {
pixcmapGetRGBA(cmap1, i, &rval1, &gval1, &bval1, &aval1);
pixcmapGetRGBA(cmap2, i, &rval2, &gval2, &bval2, &aval2);
if ((rval1 != rval2) || (gval1 != gval2) ||
(bval1 != bval2) || (aval1 != aval2))
return;
}
*pequal = TRUE;
return;
}
示例12: pixColorSegmentCluster
/*!
* \brief pixColorSegmentCluster()
*
* \param[in] pixs 32 bpp; 24-bit color
* \param[in] maxdist max euclidean dist to existing cluster
* \param[in] maxcolors max number of colors allowed in first pass
* \param[in] debugflag 1 for debug output; 0 otherwise
* \return pixd 8 bit with colormap, or NULL on error
*
* <pre>
* Notes:
* (1) This is phase 1. See description in pixColorSegment().
* (2) Greedy unsupervised classification. If the limit 'maxcolors'
* is exceeded, the computation is repeated with a larger
* allowed cluster size.
* (3) On each successive iteration, 'maxdist' is increased by a
* constant factor. See comments in pixColorSegment() for
* a guideline on parameter selection.
* Note that the diagonal of the 8-bit rgb color cube is about
* 440, so for 'maxdist' = 440, you are guaranteed to get 1 color!
* </pre>
*/
PIX *
pixColorSegmentCluster(PIX *pixs,
l_int32 maxdist,
l_int32 maxcolors,
l_int32 debugflag)
{
l_int32 w, h, newmaxdist, ret, niters, ncolors, success;
PIX *pixd;
PIXCMAP *cmap;
PROCNAME("pixColorSegmentCluster");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixGetDepth(pixs) != 32)
return (PIX *)ERROR_PTR("must be rgb color", procName, NULL);
pixGetDimensions(pixs, &w, &h, NULL);
if ((pixd = pixCreate(w, h, 8)) == NULL)
return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
cmap = pixcmapCreate(8);
pixSetColormap(pixd, cmap);
pixCopyResolution(pixd, pixs);
newmaxdist = maxdist;
niters = 0;
success = TRUE;
while (1) {
ret = pixColorSegmentTryCluster(pixd, pixs, newmaxdist,
maxcolors, debugflag);
niters++;
if (!ret) {
ncolors = pixcmapGetCount(cmap);
if (debugflag)
L_INFO("Success with %d colors after %d iters\n", procName,
ncolors, niters);
break;
}
if (niters == MAX_ALLOWED_ITERATIONS) {
L_WARNING("too many iters; newmaxdist = %d\n",
procName, newmaxdist);
success = FALSE;
break;
}
newmaxdist = (l_int32)(DIST_EXPAND_FACT * (l_float32)newmaxdist);
}
if (!success) {
pixDestroy(&pixd);
return (PIX *)ERROR_PTR("failure in phase 1", procName, NULL);
}
return pixd;
}
示例13: main
l_int32 main(int argc,
char **argv)
{
l_uint32 *colors;
l_int32 ncolors;
PIX *pix1, *pix2, *pix3;
L_REGPARAMS *rp;
if (regTestSetup(argc, argv, &rp))
return 1;
/* Find the most populated colors */
pix1 = pixRead("fish24.jpg");
pixGetMostPopulatedColors(pix1, 2, 3, 10, &colors, NULL);
pix2 = pixDisplayColorArray(colors, 10, 190, 5, 1);
pixDisplayWithTitle(pix2, 0, 0, NULL, rp->display);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 0 */
lept_free(colors);
pixDestroy(&pix2);
/* Do a simple color quantization with sigbits = 2 */
pix2 = pixSimpleColorQuantize(pix1, 2, 3, 10);
pixDisplayWithTitle(pix2, 0, 400, NULL, rp->display);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 1 */
pix3 = pixRemoveColormap(pix2, REMOVE_CMAP_TO_FULL_COLOR);
regTestComparePix(rp, pix2, pix3); /* 2 */
pixNumColors(pix3, 1, &ncolors);
regTestCompareValues(rp, ncolors, 10, 0.0); /* 3 */
pixDestroy(&pix1);
pixDestroy(&pix2);
pixDestroy(&pix3);
/* Do a simple color quantization with sigbits = 3 */
pix1 = pixRead("wyom.jpg");
pixNumColors(pix1, 1, &ncolors); /* >255, so should give 0 */
regTestCompareValues(rp, ncolors, 0, 0.0); /* 4 */
pix2 = pixSimpleColorQuantize(pix1, 3, 3, 20);
pixDisplayWithTitle(pix2, 1000, 0, NULL, rp->display);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 5 */
ncolors = pixcmapGetCount(pixGetColormap(pix2));
regTestCompareValues(rp, ncolors, 20, 0.0); /* 6 */
pixDestroy(&pix1);
pixDestroy(&pix2);
/* Find the number of perceptually significant gray intensities */
pix1 = pixRead("marge.jpg");
pix2 = pixConvertTo8(pix1, 0);
pixNumSignificantGrayColors(pix2, 20, 236, 0.0001, 1, &ncolors);
regTestCompareValues(rp, ncolors, 219, 0.0); /* 7 */
pixDestroy(&pix1);
pixDestroy(&pix2);
return regTestCleanup(rp);
}
示例14: pixColorSegmentClean
/*!
* \brief pixColorSegmentClean()
*
* \param[in] pixs 8 bpp, colormapped
* \param[in] selsize for closing
* \param[in] countarray ptr to array containing the number of pixels
* found in each color in the colormap
* \return 0 if OK, 1 on error
*
* <pre>
* Notes:
* (1) This operation is in-place.
* (2) This is phase 3 of color segmentation. It is the first
* part of a two-step noise removal process. Colors with a
* large population are closed first; this operation absorbs
* small sets of intercolated pixels of a different color.
* </pre>
*/
l_ok
pixColorSegmentClean(PIX *pixs,
l_int32 selsize,
l_int32 *countarray)
{
l_int32 i, ncolors, val;
l_uint32 val32;
NUMA *na, *nasi;
PIX *pixt1, *pixt2;
PIXCMAP *cmap;
PROCNAME("pixColorSegmentClean");
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if (pixGetDepth(pixs) != 8)
return ERROR_INT("pixs not 8 bpp", procName, 1);
if ((cmap = pixGetColormap(pixs)) == NULL)
return ERROR_INT("cmap not found", procName, 1);
if (!countarray)
return ERROR_INT("countarray not defined", procName, 1);
if (selsize <= 1)
return 0; /* nothing to do */
/* Sort colormap indices in decreasing order of pixel population */
ncolors = pixcmapGetCount(cmap);
na = numaCreate(ncolors);
for (i = 0; i < ncolors; i++)
numaAddNumber(na, countarray[i]);
nasi = numaGetSortIndex(na, L_SORT_DECREASING);
numaDestroy(&na);
if (!nasi)
return ERROR_INT("nasi not made", procName, 1);
/* For each color, in order of decreasing population,
* do a closing and absorb the added pixels. Note that
* if the closing removes pixels at the border, they'll
* still appear in the xor and will be properly (re)set. */
for (i = 0; i < ncolors; i++) {
numaGetIValue(nasi, i, &val);
pixt1 = pixGenerateMaskByValue(pixs, val, 1);
pixt2 = pixCloseSafeCompBrick(NULL, pixt1, selsize, selsize);
pixXor(pixt2, pixt2, pixt1); /* pixels to be added to type 'val' */
pixcmapGetColor32(cmap, val, &val32);
pixSetMasked(pixs, pixt2, val32); /* add them */
pixDestroy(&pixt1);
pixDestroy(&pixt2);
}
numaDestroy(&nasi);
return 0;
}
示例15: pixcmapGetExtremeValue
/*!
* pixcmapGetExtremeValue()
*
* Input: cmap
* type (L_SELECT_MIN or L_SELECT_MAX)
* &rval (<optional return> red component)
* &gval (<optional return> green component)
* &bval (<optional return> blue component)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) Returns for selected components the extreme value
* (either min or max) of the color component that is
* found in the colormap.
*/
l_int32
pixcmapGetExtremeValue(PIXCMAP *cmap,
l_int32 type,
l_int32 *prval,
l_int32 *pgval,
l_int32 *pbval)
{
l_int32 i, n, rval, gval, bval, extrval, extgval, extbval;
PROCNAME("pixcmapGetExtremeValue");
if (!prval && !pgval && !pbval)
return ERROR_INT("no result requested for return", procName, 1);
if (prval) *prval = 0;
if (pgval) *pgval = 0;
if (pbval) *pbval = 0;
if (!cmap)
return ERROR_INT("cmap not defined", procName, 1);
if (type != L_SELECT_MIN && type != L_SELECT_MAX)
return ERROR_INT("invalid type", procName, 1);
if (type == L_SELECT_MIN) {
extrval = 100000;
extgval = 100000;
extbval = 100000;
}
else {
extrval = 0;
extgval = 0;
extbval = 0;
}
n = pixcmapGetCount(cmap);
for (i = 0; i < n; i++) {
pixcmapGetColor(cmap, i, &rval, &gval, &bval);
if ((type == L_SELECT_MIN && rval < extrval) ||
(type == L_SELECT_MAX && rval > extrval))
extrval = rval;
if ((type == L_SELECT_MIN && gval < extgval) ||
(type == L_SELECT_MAX && gval > extgval))
extgval = gval;
if ((type == L_SELECT_MIN && bval < extbval) ||
(type == L_SELECT_MAX && bval > extbval))
extbval = bval;
}
if (prval) *prval = extrval;
if (pgval) *pgval = extgval;
if (pbval) *pbval = extbval;
return 0;
}