/*! * pixBilinearPtaGray() * * Input: pixs (8 bpp) * ptad (4 pts of final coordinate space) * ptas (4 pts of initial coordinate space) * grayval (0 to bring in BLACK, 255 for WHITE) * Return: pixd, or null on error */ PIX * pixBilinearPtaGray(PIX *pixs, PTA *ptad, PTA *ptas, l_uint8 grayval) { l_float32 *vc; PIX *pixd; PROCNAME("pixBilinearPtaGray"); if (!pixs) return (PIX *)ERROR_PTR("pixs not defined", procName, NULL); if (!ptas) return (PIX *)ERROR_PTR("ptas not defined", procName, NULL); if (!ptad) return (PIX *)ERROR_PTR("ptad not defined", procName, NULL); if (pixGetDepth(pixs) != 8) return (PIX *)ERROR_PTR("pixs must be 8 bpp", procName, NULL); if (ptaGetCount(ptas) != 4) return (PIX *)ERROR_PTR("ptas count not 4", procName, NULL); if (ptaGetCount(ptad) != 4) return (PIX *)ERROR_PTR("ptad count not 4", procName, NULL); /* Get backwards transform from dest to src, and apply it */ getBilinearXformCoeffs(ptad, ptas, &vc); pixd = pixBilinearGray(pixs, vc, grayval); FREE(vc); return pixd; }
/*! * pixBilinearSampledPta() * * Input: pixs (all depths) * ptad (4 pts of final coordinate space) * ptas (4 pts of initial coordinate space) * incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) * Return: pixd, or null on error * * Notes: * (1) Brings in either black or white pixels from the boundary. * (2) Retains colormap, which you can do for a sampled transform.. * (3) No 3 of the 4 points may be collinear. * (4) For 8 and 32 bpp pix, better quality is obtained by the * somewhat slower pixBilinearPta(). See that * function for relative timings between sampled and interpolated. */ PIX * pixBilinearSampledPta(PIX *pixs, PTA *ptad, PTA *ptas, l_int32 incolor) { l_float32 *vc; PIX *pixd; PROCNAME("pixBilinearSampledPta"); if (!pixs) return (PIX *)ERROR_PTR("pixs not defined", procName, NULL); if (!ptas) return (PIX *)ERROR_PTR("ptas not defined", procName, NULL); if (!ptad) return (PIX *)ERROR_PTR("ptad not defined", procName, NULL); if (incolor != L_BRING_IN_WHITE && incolor != L_BRING_IN_BLACK) return (PIX *)ERROR_PTR("invalid incolor", procName, NULL); if (ptaGetCount(ptas) != 4) return (PIX *)ERROR_PTR("ptas count not 4", procName, NULL); if (ptaGetCount(ptad) != 4) return (PIX *)ERROR_PTR("ptad count not 4", procName, NULL); /* Get backwards transform from dest to src, and apply it */ getBilinearXformCoeffs(ptad, ptas, &vc); pixd = pixBilinearSampled(pixs, vc, incolor); FREE(vc); return pixd; }
static l_float32 * Generate4PtTransformVector(l_int32 type) { l_int32 i; l_float32 *vc; PTA *ptas, *ptad; ptas = ptaCreate(4); ptad = ptaCreate(4); for (i = 0; i < 4; i++) { ptaAddPt(ptas, xs[i], ys[i]); ptaAddPt(ptad, xd[i], yd[i]); } if (type == PROJECTIVE) getProjectiveXformCoeffs(ptad, ptas, &vc); else /* BILINEAR */ getBilinearXformCoeffs(ptad, ptas, &vc); ptaDestroy(&ptas); ptaDestroy(&ptad); return vc; }