本文整理汇总了C++中pixCreateTemplate函数的典型用法代码示例。如果您正苦于以下问题:C++ pixCreateTemplate函数的具体用法?C++ pixCreateTemplate怎么用?C++ pixCreateTemplate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pixCreateTemplate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pixRotateAMGrayCorner
/*!
* pixRotateAMGrayCorner()
*
* Input: pixs
* angle (radians; clockwise is positive)
* grayval (0 to bring in BLACK, 255 for WHITE)
* Return: pixd, or null on error
*
* Notes:
* (1) Rotates the image about the UL corner.
* (2) A positive angle gives a clockwise rotation.
* (3) Specify the grayvalue to be brought in from outside the image.
*/
PIX *
pixRotateAMGrayCorner(PIX *pixs,
l_float32 angle,
l_uint8 grayval)
{
l_int32 w, h, wpls, wpld;
l_uint32 *datas, *datad;
PIX *pixd;
PROCNAME("pixRotateAMGrayCorner");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixGetDepth(pixs) != 8)
return (PIX *)ERROR_PTR("pixs must be 8 bpp", procName, NULL);
if (L_ABS(angle) < VERY_SMALL_ANGLE)
return pixClone(pixs);
pixGetDimensions(pixs, &w, &h, NULL);
datas = pixGetData(pixs);
wpls = pixGetWpl(pixs);
pixd = pixCreateTemplate(pixs);
datad = pixGetData(pixd);
wpld = pixGetWpl(pixd);
rotateAMGrayCornerLow(datad, w, h, wpld, datas, wpls, angle, grayval);
return pixd;
}
示例2: pixRotateAMColorFast
/*!
* pixRotateAMColorFast()
*
* Input: pixs
* angle (radians; clockwise is positive)
* colorval (e.g., 0 to bring in BLACK, 0xffffff00 for WHITE)
* Return: pixd, or null on error
*
* Notes:
* (1) This rotates a color image about the image center.
* (2) A positive angle gives a clockwise rotation.
* (3) It uses area mapping, dividing each pixel into
* 16 subpixels.
* (4) It is about 10% to 20% faster than the more accurate linear
* interpolation function pixRotateAMColor(),
* which uses 256 subpixels.
* (5) For some reason it shifts the image center.
* No attempt is made to rotate the alpha component.
*
* *** Warning: implicit assumption about RGB component ordering ***
*/
PIX *
pixRotateAMColorFast(PIX *pixs,
l_float32 angle,
l_uint32 colorval)
{
l_int32 w, h, wpls, wpld;
l_uint32 *datas, *datad;
PIX *pixd;
PROCNAME("pixRotateAMColorFast");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixGetDepth(pixs) != 32)
return (PIX *)ERROR_PTR("pixs must be 32 bpp", procName, NULL);
if (L_ABS(angle) < MIN_ANGLE_TO_ROTATE)
return pixClone(pixs);
pixGetDimensions(pixs, &w, &h, NULL);
datas = pixGetData(pixs);
wpls = pixGetWpl(pixs);
pixd = pixCreateTemplate(pixs);
datad = pixGetData(pixd);
wpld = pixGetWpl(pixd);
rotateAMColorFastLow(datad, w, h, wpld, datas, wpls, angle, colorval);
return pixd;
}
示例3: RemoveEnclosingCircle
// Helper to remove an enclosing circle from an image.
// If there isn't one, then the image will most likely get badly mangled.
// The returned pix must be pixDestroyed after use. NULL may be returned
// if the image doesn't meet the trivial conditions that it uses to determine
// success.
static Pix* RemoveEnclosingCircle(Pix* pixs) {
Pix* pixsi = pixInvert(NULL, pixs);
Pix* pixc = pixCreateTemplate(pixs);
pixSetOrClearBorder(pixc, 1, 1, 1, 1, PIX_SET);
pixSeedfillBinary(pixc, pixc, pixsi, 4);
pixInvert(pixc, pixc);
pixDestroy(&pixsi);
Pix* pixt = pixAnd(NULL, pixs, pixc);
l_int32 max_count;
pixCountConnComp(pixt, 8, &max_count);
// The count has to go up before we start looking for the minimum.
l_int32 min_count = MAX_INT32;
Pix* pixout = NULL;
for (int i = 1; i < kMaxCircleErosions; i++) {
pixDestroy(&pixt);
pixErodeBrick(pixc, pixc, 3, 3);
pixt = pixAnd(NULL, pixs, pixc);
l_int32 count;
pixCountConnComp(pixt, 8, &count);
if (i == 1 || count > max_count) {
max_count = count;
min_count = count;
} else if (i > 1 && count < min_count) {
min_count = count;
pixDestroy(&pixout);
pixout = pixCopy(NULL, pixt); // Save the best.
} else if (count >= min_count) {
break; // We have passed by the best.
}
}
pixDestroy(&pixt);
pixDestroy(&pixc);
return pixout;
}
示例4: pixUninterlaceGIF
static PIX *
pixUninterlaceGIF(PIX *pixs)
{
l_int32 w, h, d, wpl, j, k, srow, drow;
l_uint32 *datas, *datad, *lines, *lined;
PIX *pixd;
PROCNAME("pixUninterlaceGIF");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
pixGetDimensions(pixs, &w, &h, &d);
wpl = pixGetWpl(pixs);
pixd = pixCreateTemplate(pixs);
datas = pixGetData(pixs);
datad = pixGetData(pixd);
for (k = 0, srow = 0; k < 4; k++) {
for (drow = InterlacedOffset[k]; drow < h;
drow += InterlacedJumps[k], srow++) {
lines = datas + srow * wpl;
lined = datad + drow * wpl;
for (j = 0; j < w; j++)
memcpy(lined, lines, 4 * wpl);
}
}
return pixd;
}
示例5: main
main(int argc,
char **argv)
{
l_int32 i, index;
l_float32 cputime, epo;
char *filein, *fileout;
PIX *pixs, *pixd;
SEL *sel;
SELA *sela;
static char mainName[] = "morphtest1";
if (argc != 3)
exit(ERROR_INT(" Syntax: morphtest1 filein fileout", mainName, 1));
filein = argv[1];
fileout = argv[2];
if ((pixs = pixRead(filein)) == NULL)
exit(ERROR_INT("pix not made", mainName, 1));
sela = selaAddBasic(NULL);
/* ------------------------ Timing -------------------------------*/
#if 1
selaFindSelByName(sela, "sel_9h", &index, &sel);
selWriteStream(stderr, sel);
pixd = pixCreateTemplate(pixs);
startTimer();
for (i = 0; i < NTIMES; i++) {
pixDilate(pixd, pixs, sel);
/* if ((i % 10) == 0) fprintf(stderr, "%d iters\n", i); */
}
cputime = stopTimer();
/* Get the elementary pixel operations/sec */
epo = BASIC_OPS * SEL_SIZE * NTIMES * IMAGE_SIZE /(cputime * CPU_SPEED);
fprintf(stderr, "Time: %7.3f sec\n", cputime);
fprintf(stderr, "Speed: %7.3f epo/cycle\n", epo);
pixWrite(fileout, pixd, IFF_PNG);
pixDestroy(&pixd);
#endif
/* ------------------ Example operation from repository --------------*/
#if 1
/* Select a structuring element */
selaFindSelByName(sela, "sel_50h", &index, &sel);
selWriteStream(stderr, sel);
/* Do these operations. See below for other ops
* that can be substituted here. */
pixd = pixOpen(NULL, pixs, sel);
pixXor(pixd, pixd, pixs);
pixWrite(fileout, pixd, IFF_PNG);
pixDestroy(&pixd);
#endif
pixDestroy(&pixs);
exit(0);
}
示例6: pixFHMTGen_1
/*!
* pixFHMTGen_1()
*
* Input: pixd (usual 3 choices: null, == pixs, != pixs)
* pixs (1 bpp)
* sel name
* Return: pixd
*
* Notes:
* (1) This is a dwa implementation of the hit-miss transform
* on pixs by the sel.
* (2) The sel must be limited in size to not more than 31 pixels
* about the origin. It must have at least one hit, and it
* can have any number of misses.
* (3) This handles all required setting of the border pixels
* before erosion and dilation.
*/
PIX *
pixFHMTGen_1(PIX *pixd,
PIX *pixs,
char *selname)
{
l_int32 i, index, found, w, h, wpls, wpld;
l_uint32 *datad, *datas, *datat;
PIX *pixt;
PROCNAME("pixFHMTGen_1");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, pixd);
if (pixGetDepth(pixs) != 1)
return (PIX *)ERROR_PTR("pixs must be 1 bpp", procName, pixd);
found = FALSE;
for (i = 0; i < NUM_SELS_GENERATED; i++) {
if (strcmp(selname, SEL_NAMES[i]) == 0) {
found = TRUE;
index = i;
break;
}
}
if (found == FALSE)
return (PIX *)ERROR_PTR("sel index not found", procName, pixd);
if (!pixd) {
if ((pixd = pixCreateTemplate(pixs)) == NULL)
return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
}
else /* for in-place or pre-allocated */
pixResizeImageData(pixd, pixs);
wpls = pixGetWpl(pixs);
wpld = pixGetWpl(pixd);
/* The images must be surrounded with 32 additional border
* pixels, that we'll read from. We fabricate a "proper"
* image as the subimage within the border, having the
* following parameters: */
w = pixGetWidth(pixs) - 64;
h = pixGetHeight(pixs) - 64;
datas = pixGetData(pixs) + 32 * wpls + 1;
datad = pixGetData(pixd) + 32 * wpld + 1;
if (pixd == pixs) { /* need temp image if in-place */
if ((pixt = pixCopy(NULL, pixs)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", procName, pixd);
datat = pixGetData(pixt) + 32 * wpls + 1;
fhmtgen_low_1(datad, w, h, wpld, datat, wpls, index);
pixDestroy(&pixt);
}
else { /* not in-place */
fhmtgen_low_1(datad, w, h, wpld, datas, wpls, index);
}
return pixd;
}
示例7: pixAdaptiveMeanFilter
/*!
* pixAdaptiveMeanFilter()
*
* Input: pixs (8 bpp grayscale)
* wc, hc (half width/height of convolution kernel)
* varn (value of overall noise variance)
* Return: pixd (8 bpp, filtered image)
*
* Notes:
* (1) The filter reduces gaussian noise, achieving results similar
* to the arithmetic and geometric mean filters but avoiding the
* considerable image blurring effect introduced by those filters.
* (2) The filter can be expressed mathematically by:
* f'(x, y) = g(x, y) - varN / varL * [ g(x, y) - meanL ]
* where:
* -- g(x, y) is the pixel at the center of local region S of
* width (2 * wc + 1) and height (2 * wh + 1)
* -- varN and varL are the overall noise variance (given in input)
* and local variance of S, respectively
* -- meanL is the local mean of S
* (3) Typically @varn is estimated by studying the PDFs produced by
* the camera or equipment sensors.
*/
PIX *
pixAdaptiveMeanFilter(PIX *pixs,
l_int32 wc,
l_int32 hc,
l_float32 varn)
{
l_int32 i, j, w, h, d, wplt, wpld, wincr, hincr;
l_uint32 val;
l_uint32 *datat, *datad, *linet, *lined;
l_float32 norm, meanl, varl, ratio;
PIX *pixt, *pixd;
PROCNAME("pixAdaptiveMeanFilter");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
pixGetDimensions(pixs, &w, &h, &d);
if (d != 8)
return (PIX *)ERROR_PTR("pixs not 8 bpp", procName, NULL);
if (wc < 1 || hc < 1)
return (PIX *)ERROR_PTR("wc and hc not >= 1", procName, NULL);
/* Add wc to each side, and hc to top and bottom of the image,
* mirroring for accuracy and to avoid special-casing the boundary. */
if ((pixt = pixAddMirroredBorder(pixs, wc, wc, hc, hc)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", procName, NULL);
/* Place the filter center at (0, 0). This is just a
* convenient location, because it allows us to perform
* the filtering over x:(0 ... w - 1) and y:(0 ... h - 1). */
pixd = pixCreateTemplate(pixs);
wplt = pixGetWpl(pixt);
wpld = pixGetWpl(pixd);
datat = pixGetData(pixt);
datad = pixGetData(pixd);
wincr = 2 * wc + 1;
hincr = 2 * hc + 1;
norm = 1.0 / (wincr * hincr);
for (i = 0; i < h; i++) {
linet = datat + (i + hc) * wplt;
lined = datad + i * wpld;
for (j = 0; j < w; j++) {
/* Calculate mean intensity value */
meanl = calculateLocalMeanLow(datat, wplt, wincr, hincr, i, j);
/* Calculate local variance */
varl = calculateLocalVarianceLow(datat, wplt, wincr, hincr, i, j, meanl);
/* Account for special case in which varN is more than varL */
ratio = (varn > varl) ? 1 : varn / varl;
val = GET_DATA_BYTE(linet, j + wc);
SET_DATA_BYTE(lined, j, (l_uint8) (val - ratio * (val - meanl)));
}
}
pixDestroy(&pixt);
return pixd;
}
示例8: pixSelectByWidthHeightRatio
/*!
* pixSelectByWidthHeightRatio()
*
* Input: pixs (1 bpp)
* thresh (threshold ratio of width/height)
* connectivity (4 or 8)
* type (L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE)
* &changed (<optional return> 1 if changed; 0 if clone returned)
* Return: pixd, or null on error
*
* Notes:
* (1) The args specify constraints on the width-to-height ratio
* for components that are kept.
* (2) If unchanged, returns a copy of pixs. Otherwise,
* returns a new pix with the filtered components.
* (3) This filters components based on the width-to-height ratios.
* (4) Use L_SELECT_IF_LT or L_SELECT_IF_LTE to save components
* with less than the threshold ratio, and
* L_SELECT_IF_GT or L_SELECT_IF_GTE to remove them.
*/
PIX *
pixSelectByWidthHeightRatio(PIX *pixs,
l_float32 thresh,
l_int32 connectivity,
l_int32 type,
l_int32 *pchanged)
{
l_int32 w, h, empty, changed, count;
BOXA *boxa;
PIX *pixd;
PIXA *pixas, *pixad;
PROCNAME("pixSelectByWidthHeightRatio");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (connectivity != 4 && connectivity != 8)
return (PIX *)ERROR_PTR("connectivity not 4 or 8", procName, NULL);
if (type != L_SELECT_IF_LT && type != L_SELECT_IF_GT &&
type != L_SELECT_IF_LTE && type != L_SELECT_IF_GTE)
return (PIX *)ERROR_PTR("invalid type", procName, NULL);
if (pchanged) *pchanged = FALSE;
/* Check if any components exist */
pixZero(pixs, &empty);
if (empty)
return pixCopy(NULL, pixs);
/* Filter components */
boxa = pixConnComp(pixs, &pixas, connectivity);
pixad = pixaSelectByWidthHeightRatio(pixas, thresh, type, &changed);
boxaDestroy(&boxa);
pixaDestroy(&pixas);
/* Render the result */
if (!changed) {
pixaDestroy(&pixad);
return pixCopy(NULL, pixs);
}
else {
if (pchanged) *pchanged = TRUE;
pixGetDimensions(pixs, &w, &h, NULL);
count = pixaGetCount(pixad);
if (count == 0) /* return empty pix */
pixd = pixCreateTemplate(pixs);
else {
pixd = pixaDisplay(pixad, w, h);
pixCopyResolution(pixd, pixs);
pixCopyColormap(pixd, pixs);
pixCopyText(pixd, pixs);
pixCopyInputFormat(pixd, pixs);
}
pixaDestroy(&pixad);
return pixd;
}
}
示例9: bilateralApply
/*!
* bilateralApply()
*
* Input: bil
* Return: pixd
*/
static PIX *
bilateralApply(L_BILATERAL *bil)
{
l_int32 i, j, k, ired, jred, w, h, wpls, wpld, ncomps, reduction;
l_int32 vals, vald, lowval, hival;
l_int32 *kindex;
l_float32 fract;
l_float32 *kfract;
l_uint32 *lines, *lined, *datas, *datad;
l_uint32 ***lineset = NULL; /* for set of PBC */
PIX *pixs, *pixd;
PIXA *pixac;
PROCNAME("bilateralApply");
if (!bil)
return (PIX *)ERROR_PTR("bil not defined", procName, NULL);
pixs = bil->pixs;
ncomps = bil->ncomps;
kindex = bil->kindex;
kfract = bil->kfract;
reduction = bil->reduction;
pixac = bil->pixac;
lineset = bil->lineset;
if (pixaGetCount(pixac) != ncomps)
return (PIX *)ERROR_PTR("PBC images do not exist", procName, NULL);
if ((pixd = pixCreateTemplate(pixs)) == NULL)
return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
datas = pixGetData(pixs);
wpls = pixGetWpl(pixs);
datad = pixGetData(pixd);
wpld = pixGetWpl(pixd);
pixGetDimensions(pixs, &w, &h, NULL);
for (i = 0; i < h; i++) {
lines = datas + i * wpls;
lined = datad + i * wpld;
ired = i / reduction;
for (j = 0; j < w; j++) {
jred = j / reduction;
vals = GET_DATA_BYTE(lines, j);
k = kindex[vals];
lowval = GET_DATA_BYTE(lineset[k][ired], jred);
hival = GET_DATA_BYTE(lineset[k + 1][ired], jred);
fract = kfract[vals];
vald = (l_int32)((1.0 - fract) * lowval + fract * hival + 0.5);
SET_DATA_BYTE(lined, j, vald);
}
}
return pixd;
}
示例10: pixBilinearColor
/*!
* pixBilinearColor()
*
* Input: pixs (32 bpp)
* vc (vector of 8 coefficients for bilinear transformation)
* colorval (e.g., 0 to bring in BLACK, 0xffffff00 for WHITE)
* Return: pixd, or null on error
*/
PIX *
pixBilinearColor(PIX *pixs,
l_float32 *vc,
l_uint32 colorval) {
l_int32 i, j, w, h, d, wpls, wpld;
l_uint32 val;
l_uint32 *datas, *datad, *lined;
l_float32 x, y;
PIX *pix1, *pix2, *pixd;
PROCNAME("pixBilinearColor");
if (!pixs)
return (PIX *) ERROR_PTR("pixs not defined", procName, NULL);
pixGetDimensions(pixs, &w, &h, &d);
if (d != 32)
return (PIX *) ERROR_PTR("pixs must be 32 bpp", procName, NULL);
if (!vc)
return (PIX *) ERROR_PTR("vc not defined", procName, NULL);
datas = pixGetData(pixs);
wpls = pixGetWpl(pixs);
pixd = pixCreateTemplate(pixs);
pixSetAllArbitrary(pixd, colorval);
datad = pixGetData(pixd);
wpld = pixGetWpl(pixd);
/* Iterate over destination pixels */
for (i = 0; i < h; i++) {
lined = datad + i * wpld;
for (j = 0; j < w; j++) {
/* Compute float src pixel location corresponding to (i,j) */
bilinearXformPt(vc, j, i, &x, &y);
linearInterpolatePixelColor(datas, wpls, w, h, x, y, colorval,
&val);
*(lined + j) = val;
}
}
/* If rgba, transform the pixs alpha channel and insert in pixd */
if (pixGetSpp(pixs) == 4) {
pix1 = pixGetRGBComponent(pixs, L_ALPHA_CHANNEL);
pix2 = pixBilinearGray(pix1, vc, 255); /* bring in opaque */
pixSetRGBComponent(pixd, pix2, L_ALPHA_CHANNEL);
pixDestroy(&pix1);
pixDestroy(&pix2);
}
return pixd;
}
示例11: pixCopy
/*!
* pixCopy()
*
* Input: pixd (<optional>; can be null, or equal to pixs,
* or different from pixs)
* pixs
* Return: pixd, or null on error
*
* Notes:
* (1) There are three cases:
* (a) pixd == null (makes a new pix; refcount = 1)
* (b) pixd == pixs (no-op)
* (c) pixd != pixs (data copy; no change in refcount)
* If the refcount of pixd > 1, case (c) will side-effect
* these handles.
* (2) The general pattern of use is:
* pixd = pixCopy(pixd, pixs);
* This will work for all three cases.
* For clarity when the case is known, you can use:
* (a) pixd = pixCopy(NULL, pixs);
* (c) pixCopy(pixd, pixs);
* (3) For case (c), we check if pixs and pixd are the same
* size (w,h,d). If so, the data is copied directly.
* Otherwise, the data is reallocated to the correct size
* and the copy proceeds. The refcount of pixd is unchanged.
* (4) This operation, like all others that may involve a pre-existing
* pixd, will side-effect any existing clones of pixd.
*/
PIX *
pixCopy(PIX *pixd, /* can be null */
PIX *pixs)
{
l_int32 bytes;
l_uint32 *datas, *datad;
PROCNAME("pixCopy");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixs == pixd)
return pixd;
/* Total bytes in image data */
bytes = 4 * pixGetWpl(pixs) * pixGetHeight(pixs);
/* If we're making a new pix ... */
if (!pixd) {
if ((pixd = pixCreateTemplate(pixs)) == NULL)
return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
datas = pixGetData(pixs);
datad = pixGetData(pixd);
memcpy((char *)datad, (char *)datas, bytes);
return pixd;
}
/* Reallocate image data if sizes are different */
if (pixResizeImageData(pixd, pixs) == 1)
return (PIX *)ERROR_PTR("reallocation of data failed", procName, NULL);
/* Copy non-image data fields */
pixCopyColormap(pixd, pixs);
pixCopyResolution(pixd, pixs);
pixCopyInputFormat(pixd, pixs);
pixCopyText(pixd, pixs);
/* Copy image data */
datas = pixGetData(pixs);
datad = pixGetData(pixd);
memcpy((char*)datad, (char*)datas, bytes);
return pixd;
}
示例12: pixProjectiveColor
/*!
* pixProjectiveColor()
*
* Input: pixs (32 bpp)
* vc (vector of 8 coefficients for projective transformation)
* colorval (e.g., 0 to bring in BLACK, 0xffffff00 for WHITE)
* Return: pixd, or null on error
*/
PIX *
pixProjectiveColor(PIX *pixs,
l_float32 *vc,
l_uint32 colorval)
{
l_int32 i, j, w, h, d, wpls, wpld;
l_uint32 val;
l_uint32 *datas, *datad, *lined;
l_float32 x, y;
PIX *pixd;
PROCNAME("pixProjectiveColor");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
pixGetDimensions(pixs, &w, &h, &d);
if (d != 32)
return (PIX *)ERROR_PTR("pixs must be 32 bpp", procName, NULL);
if (!vc)
return (PIX *)ERROR_PTR("vc not defined", procName, NULL);
datas = pixGetData(pixs);
wpls = pixGetWpl(pixs);
pixd = pixCreateTemplate(pixs);
pixSetAllArbitrary(pixd, colorval);
datad = pixGetData(pixd);
wpld = pixGetWpl(pixd);
/* Iterate over destination pixels */
for (i = 0; i < h; i++) {
lined = datad + i * wpld;
for (j = 0; j < w; j++) {
/* Compute float src pixel location corresponding to (i,j) */
projectiveXformPt(vc, j, i, &x, &y);
linearInterpolatePixelColor(datas, wpls, w, h, x, y, colorval,
&val);
*(lined + j) = val;
}
}
return pixd;
}
示例13: pixProjectiveGray
/*!
* pixProjectiveGray()
*
* Input: pixs (8 bpp)
* vc (vector of 8 coefficients for projective transformation)
* grayval (0 to bring in BLACK, 255 for WHITE)
* Return: pixd, or null on error
*/
PIX *
pixProjectiveGray(PIX *pixs,
l_float32 *vc,
l_uint8 grayval)
{
l_int32 i, j, w, h, wpls, wpld, val;
l_uint32 *datas, *datad, *lined;
l_float32 x, y;
PIX *pixd;
PROCNAME("pixProjectiveGray");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
pixGetDimensions(pixs, &w, &h, NULL);
if (pixGetDepth(pixs) != 8)
return (PIX *)ERROR_PTR("pixs must be 8 bpp", procName, NULL);
if (!vc)
return (PIX *)ERROR_PTR("vc not defined", procName, NULL);
datas = pixGetData(pixs);
wpls = pixGetWpl(pixs);
pixd = pixCreateTemplate(pixs);
pixSetAllArbitrary(pixd, grayval);
datad = pixGetData(pixd);
wpld = pixGetWpl(pixd);
/* Iterate over destination pixels */
for (i = 0; i < h; i++) {
lined = datad + i * wpld;
for (j = 0; j < w; j++) {
/* Compute float src pixel location corresponding to (i,j) */
projectiveXformPt(vc, j, i, &x, &y);
linearInterpolatePixelGray(datas, wpls, w, h, x, y, grayval, &val);
SET_DATA_BYTE(lined, j, val);
}
}
return pixd;
}
示例14: ReconstructByValue
static PIX *
ReconstructByValue(L_REGPARAMS *rp,
const char *fname)
{
l_int32 i, n, rval, gval, bval;
PIX *pixs, *pixm, *pixd;
PIXCMAP *cmap;
pixs = pixRead(fname);
cmap = pixGetColormap(pixs);
n = pixcmapGetCount(cmap);
pixd = pixCreateTemplate(pixs);
for (i = 0; i < n; i++) {
pixm = pixGenerateMaskByValue(pixs, i, 1);
pixcmapGetColor(cmap, i, &rval, &gval, &bval);
pixSetMaskedCmap(pixd, pixm, 0, 0, rval, gval, bval);
pixDestroy(&pixm);
}
regTestComparePix(rp, pixs, pixd);
pixDestroy(&pixs);
return pixd;
}
示例15: pixRotateAMColorCorner
/*!
* pixRotateAMColorCorner()
*
* Input: pixs
* angle (radians; clockwise is positive)
* colorval (e.g., 0 to bring in BLACK, 0xffffff00 for WHITE)
* Return: pixd, or null on error
*
* Notes:
* (1) Rotates the image about the UL corner.
* (2) A positive angle gives a clockwise rotation.
* (3) Specify the color to be brought in from outside the image.
*/
PIX *
pixRotateAMColorCorner(PIX *pixs,
l_float32 angle,
l_uint32 fillval)
{
l_int32 w, h, wpls, wpld;
l_uint32 *datas, *datad;
PIX *pix1, *pix2, *pixd;
PROCNAME("pixRotateAMColorCorner");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixGetDepth(pixs) != 32)
return (PIX *)ERROR_PTR("pixs must be 32 bpp", procName, NULL);
if (L_ABS(angle) < MIN_ANGLE_TO_ROTATE)
return pixClone(pixs);
pixGetDimensions(pixs, &w, &h, NULL);
datas = pixGetData(pixs);
wpls = pixGetWpl(pixs);
pixd = pixCreateTemplate(pixs);
datad = pixGetData(pixd);
wpld = pixGetWpl(pixd);
rotateAMColorCornerLow(datad, w, h, wpld, datas, wpls, angle, fillval);
if (pixGetSpp(pixs) == 4) {
pix1 = pixGetRGBComponent(pixs, L_ALPHA_CHANNEL);
pix2 = pixRotateAMGrayCorner(pix1, angle, 255); /* bring in opaque */
pixSetRGBComponent(pixd, pix2, L_ALPHA_CHANNEL);
pixDestroy(&pix1);
pixDestroy(&pix2);
}
return pixd;
}