122 #include <config_auto.h> 125 #include "allheaders.h" 158 PROCNAME(
"pixRankFilter");
161 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
162 if (pixGetColormap(pixs) != NULL)
163 return (
PIX *)ERROR_PTR(
"pixs has colormap", procName, NULL);
164 d = pixGetDepth(pixs);
165 if (d != 8 && d != 32)
166 return (
PIX *)ERROR_PTR(
"pixs not 8 or 32 bpp", procName, NULL);
167 if (wf < 1 || hf < 1)
168 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", procName, NULL);
169 if (rank < 0.0 || rank > 1.0)
170 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", procName, NULL);
171 if (wf == 1 && hf == 1)
208 PIX *pixr, *pixg, *pixb, *pixrf, *pixgf, *pixbf, *pixd;
210 PROCNAME(
"pixRankFilterRGB");
213 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
214 if (pixGetDepth(pixs) != 32)
215 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", procName, NULL);
216 if (wf < 1 || hf < 1)
217 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", procName, NULL);
218 if (rank < 0.0 || rank > 1.0)
219 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", procName, NULL);
220 if (wf == 1 && hf == 1)
276 l_int32 w, h, d, i, j, k, m, n, rankloc, wplt, wpld, val, sum;
277 l_int32 *histo, *histo16;
278 l_uint32 *datat, *linet, *datad, *lined;
281 PROCNAME(
"pixRankFilterGray");
284 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
285 if (pixGetColormap(pixs) != NULL)
286 return (
PIX *)ERROR_PTR(
"pixs has colormap", procName, NULL);
289 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", procName, NULL);
290 if (wf < 1 || hf < 1)
291 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", procName, NULL);
292 if (rank < 0.0 || rank > 1.0)
293 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", procName, NULL);
294 if (wf == 1 && hf == 1)
303 if (wf % 2 && hf % 2) {
306 else if (rank == 1.0)
309 if (rank == 0.0) rank = 0.0001;
310 if (rank == 1.0) rank = 0.9999;
317 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
320 histo = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
321 histo16 = (l_int32 *)LEPT_CALLOC(16,
sizeof(l_int32));
322 rankloc = (l_int32)(rank * wf * hf);
329 wplt = pixGetWpl(pixt);
331 wpld = pixGetWpl(pixd);
336 for (j = 0; j < w; j++) {
338 for (n = 0; n < 256; n++)
340 for (n = 0; n < 16; n++)
343 for (i = 0; i < h; i++) {
345 lined = datad + i * wpld;
347 for (k = 0; k < hf; k++) {
348 linet = datat + (i + k) * wplt;
349 for (m = 0; m < wf; m++) {
356 linet = datat + (i - 1) * wplt;
357 for (m = 0; m < wf; m++) {
362 linet = datat + (i + hf - 1) * wplt;
363 for (m = 0; m < wf; m++) {
372 for (n = 0; n < 16; n++) {
380 L_WARNING(
"n = 16; reducing\n", procName);
385 for (m = 0; m < 16; m++) {
396 for (i = 0; i < h; i++) {
398 for (n = 0; n < 256; n++)
400 for (n = 0; n < 16; n++)
402 lined = datad + i * wpld;
403 for (j = 0; j < w; j++) {
406 for (k = 0; k < hf; k++) {
407 linet = datat + (i + k) * wplt;
408 for (m = 0; m < wf; m++) {
415 for (k = 0; k < hf; k++) {
416 linet = datat + (i + k) * wplt;
428 for (n = 0; n < 16; n++) {
436 L_WARNING(
"n = 16; reducing\n", procName);
441 for (m = 0; m < 16; m++) {
475 PROCNAME(
"pixMedianFilter");
478 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
510 l_float32 scalefactor)
512 l_int32 w, h, d, wfs, hfs;
513 PIX *pix1, *pix2, *pixd;
515 PROCNAME(
"pixRankFilterWithScaling");
518 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
519 if (pixGetColormap(pixs) != NULL)
520 return (
PIX *)ERROR_PTR(
"pixs has colormap", procName, NULL);
521 d = pixGetDepth(pixs);
522 if (d != 8 && d != 32)
523 return (
PIX *)ERROR_PTR(
"pixs not 8 or 32 bpp", procName, NULL);
524 if (wf < 1 || hf < 1)
525 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", procName, NULL);
526 if (rank < 0.0 || rank > 1.0)
527 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", procName, NULL);
528 if (wf == 1 && hf == 1)
530 if (scalefactor < 0.2 || scalefactor > 0.7) {
531 L_ERROR(
"invalid scale factor; no scaling used\n", procName);
536 wfs = L_MAX(1, (l_int32)(scalefactor * wf + 0.5));
537 hfs = L_MAX(1, (l_int32)(scalefactor * hf + 0.5));
PIX * pixDilateGray(PIX *pixs, l_int32 hsize, l_int32 vsize)
pixDilateGray()
PIX * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
PIX * pixMedianFilter(PIX *pixs, l_int32 wf, l_int32 hf)
pixMedianFilter()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixRankFilterGray(PIX *pixs, l_int32 wf, l_int32 hf, l_float32 rank)
pixRankFilterGray()
PIX * pixScaleAreaMap(PIX *pix, l_float32 scalex, l_float32 scaley)
pixScaleAreaMap()
PIX * pixAddMirroredBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
pixAddMirroredBorder()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
PIX * pixRankFilterWithScaling(PIX *pixs, l_int32 wf, l_int32 hf, l_float32 rank, l_float32 scalefactor)
pixRankFilterWithScaling()
PIX * pixGetRGBComponent(PIX *pixs, l_int32 comp)
pixGetRGBComponent()
PIX * pixRankFilterRGB(PIX *pixs, l_int32 wf, l_int32 hf, l_float32 rank)
pixRankFilterRGB()
#define SET_DATA_BYTE(pdata, n, val)
#define GET_DATA_BYTE(pdata, n)
PIX * pixCreateRGBImage(PIX *pixr, PIX *pixg, PIX *pixb)
pixCreateRGBImage()
PIX * pixScaleToSize(PIX *pixs, l_int32 wd, l_int32 hd)
pixScaleToSize()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIX * pixRankFilter(PIX *pixs, l_int32 wf, l_int32 hf, l_float32 rank)
pixRankFilter()
PIX * pixErodeGray(PIX *pixs, l_int32 hsize, l_int32 vsize)
pixErodeGray()