121 #include "allheaders.h" 154 PROCNAME(
"pixRankFilter");
157 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
158 if (pixGetColormap(pixs) != NULL)
159 return (
PIX *)ERROR_PTR(
"pixs has colormap", procName, NULL);
160 d = pixGetDepth(pixs);
161 if (d != 8 && d != 32)
162 return (
PIX *)ERROR_PTR(
"pixs not 8 or 32 bpp", procName, NULL);
163 if (wf < 1 || hf < 1)
164 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", procName, NULL);
165 if (rank < 0.0 || rank > 1.0)
166 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", procName, NULL);
167 if (wf == 1 && hf == 1)
204 PIX *pixr, *pixg, *pixb, *pixrf, *pixgf, *pixbf, *pixd;
206 PROCNAME(
"pixRankFilterRGB");
209 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
210 if (pixGetDepth(pixs) != 32)
211 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", procName, NULL);
212 if (wf < 1 || hf < 1)
213 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", procName, NULL);
214 if (rank < 0.0 || rank > 1.0)
215 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", procName, NULL);
216 if (wf == 1 && hf == 1)
272 l_int32 w, h, d, i, j, k, m, n, rankloc, wplt, wpld, val, sum;
273 l_int32 *histo, *histo16;
274 l_uint32 *datat, *linet, *datad, *lined;
277 PROCNAME(
"pixRankFilterGray");
280 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
281 if (pixGetColormap(pixs) != NULL)
282 return (
PIX *)ERROR_PTR(
"pixs has colormap", procName, NULL);
285 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", procName, NULL);
286 if (wf < 1 || hf < 1)
287 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", procName, NULL);
288 if (rank < 0.0 || rank > 1.0)
289 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", procName, NULL);
290 if (wf == 1 && hf == 1)
299 if (wf % 2 && hf % 2) {
302 else if (rank == 1.0)
305 if (rank == 0.0) rank = 0.0001;
306 if (rank == 1.0) rank = 0.9999;
313 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
316 histo = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
317 histo16 = (l_int32 *)LEPT_CALLOC(16,
sizeof(l_int32));
318 rankloc = (l_int32)(rank * wf * hf);
325 wplt = pixGetWpl(pixt);
327 wpld = pixGetWpl(pixd);
332 for (j = 0; j < w; j++) {
334 for (n = 0; n < 256; n++)
336 for (n = 0; n < 16; n++)
339 for (i = 0; i < h; i++) {
341 lined = datad + i * wpld;
343 for (k = 0; k < hf; k++) {
344 linet = datat + (i + k) * wplt;
345 for (m = 0; m < wf; m++) {
352 linet = datat + (i - 1) * wplt;
353 for (m = 0; m < wf; m++) {
358 linet = datat + (i + hf - 1) * wplt;
359 for (m = 0; m < wf; m++) {
368 for (n = 0; n < 16; n++) {
376 L_WARNING(
"n = 16; reducing\n", procName);
381 for (m = 0; m < 16; m++) {
392 for (i = 0; i < h; i++) {
394 for (n = 0; n < 256; n++)
396 for (n = 0; n < 16; n++)
398 lined = datad + i * wpld;
399 for (j = 0; j < w; j++) {
402 for (k = 0; k < hf; k++) {
403 linet = datat + (i + k) * wplt;
404 for (m = 0; m < wf; m++) {
411 for (k = 0; k < hf; k++) {
412 linet = datat + (i + k) * wplt;
424 for (n = 0; n < 16; n++) {
432 L_WARNING(
"n = 16; reducing\n", procName);
437 for (m = 0; m < 16; m++) {
471 PROCNAME(
"pixMedianFilter");
474 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
506 l_float32 scalefactor)
508 l_int32 w, h, d, wfs, hfs;
509 PIX *pix1, *pix2, *pixd;
511 PROCNAME(
"pixRankFilterWithScaling");
514 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
515 if (pixGetColormap(pixs) != NULL)
516 return (
PIX *)ERROR_PTR(
"pixs has colormap", procName, NULL);
517 d = pixGetDepth(pixs);
518 if (d != 8 && d != 32)
519 return (
PIX *)ERROR_PTR(
"pixs not 8 or 32 bpp", procName, NULL);
520 if (wf < 1 || hf < 1)
521 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", procName, NULL);
522 if (rank < 0.0 || rank > 1.0)
523 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", procName, NULL);
524 if (wf == 1 && hf == 1)
526 if (scalefactor < 0.2 || scalefactor > 0.7) {
527 L_ERROR(
"invalid scale factor; no scaling used\n", procName);
532 wfs = L_MAX(1, (l_int32)(scalefactor * wf + 0.5));
533 hfs = L_MAX(1, (l_int32)(scalefactor * hf + 0.5));
PIX * pixDilateGray(PIX *pixs, l_int32 hsize, l_int32 vsize)
pixDilateGray()
PIX * pixMedianFilter(PIX *pixs, l_int32 wf, l_int32 hf)
pixMedianFilter()
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 * pixCreateTemplate(PIX *pixs)
pixCreateTemplate()
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 * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
PIX * pixErodeGray(PIX *pixs, l_int32 hsize, l_int32 vsize)
pixErodeGray()