206PIX *pixr, *pixg, *pixb, *pixrf, *pixgf, *pixbf, *pixd;
209 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
210 if (pixGetDepth(pixs) != 32)
211 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
212 if (wf < 1 || hf < 1)
213 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", __func__, NULL);
214 if (rank < 0.0 || rank > 1.0)
215 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", __func__, NULL);
216 if (wf == 1 && hf == 1)
217 return pixCopy(NULL, pixs);
219 pixr = pixGetRGBComponent(pixs,
COLOR_RED);
227 pixd = pixCreateRGBImage(pixrf, pixgf, pixbf);
272l_int32 w, h, d, i, j, k, m, n, rankloc, wplt, wpld, val, sum;
273l_int32 *histo, *histo16;
274l_uint32 *datat, *linet, *datad, *lined;
278 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
279 if (pixGetColormap(pixs) != NULL)
280 return (
PIX *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
281 pixGetDimensions(pixs, &w, &h, &d);
283 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
284 if (wf < 1 || hf < 1)
285 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", __func__, NULL);
286 if (rank < 0.0 || rank > 1.0)
287 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", __func__, NULL);
288 if (wf == 1 && hf == 1)
289 return pixCopy(NULL, pixs);
297 if (wf % 2 && hf % 2) {
299 return pixErodeGray(pixs, wf, hf);
300 else if (rank == 1.0)
301 return pixDilateGray(pixs, wf, hf);
303 if (rank == 0.0) rank = 0.0001f;
304 if (rank == 1.0) rank = 0.9999f;
309 if ((pixt = pixAddMirroredBorder(pixs, wf / 2, wf / 2, hf / 2, hf / 2))
311 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
314 histo = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
315 histo16 = (l_int32 *)LEPT_CALLOC(16,
sizeof(l_int32));
316 rankloc = (l_int32)(rank * wf * hf);
321 pixd = pixCreateTemplate(pixs);
322 datat = pixGetData(pixt);
323 wplt = pixGetWpl(pixt);
324 datad = pixGetData(pixd);
325 wpld = pixGetWpl(pixd);
330 for (j = 0; j < w; j++) {
332 for (n = 0; n < 256; n++)
334 for (n = 0; n < 16; n++)
337 for (i = 0; i < h; i++) {
339 lined = datad + i * wpld;
341 for (k = 0; k < hf; k++) {
342 linet = datat + (i + k) * wplt;
343 for (m = 0; m < wf; m++) {
350 linet = datat + (i - 1) * wplt;
351 for (m = 0; m < wf; m++) {
356 linet = datat + (i + hf - 1) * wplt;
357 for (m = 0; m < wf; m++) {
366 for (n = 0; n < 16; n++) {
374 L_WARNING(
"n = 16; reducing\n", __func__);
379 for (m = 0; m < 16; m++) {
390 for (i = 0; i < h; i++) {
392 for (n = 0; n < 256; n++)
394 for (n = 0; n < 16; n++)
396 lined = datad + i * wpld;
397 for (j = 0; j < w; j++) {
400 for (k = 0; k < hf; k++) {
401 linet = datat + (i + k) * wplt;
402 for (m = 0; m < wf; m++) {
409 for (k = 0; k < hf; k++) {
410 linet = datat + (i + k) * wplt;
422 for (n = 0; n < 16; n++) {
430 L_WARNING(
"n = 16; reducing\n", __func__);
435 for (m = 0; m < 16; m++) {
502 l_float32 scalefactor)
504l_int32 w, h, d, wfs, hfs;
505PIX *pix1, *pix2, *pixd;
508 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
509 if (pixGetColormap(pixs) != NULL)
510 return (
PIX *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
511 d = pixGetDepth(pixs);
512 if (d != 8 && d != 32)
513 return (
PIX *)ERROR_PTR(
"pixs not 8 or 32 bpp", __func__, NULL);
514 if (wf < 1 || hf < 1)
515 return (
PIX *)ERROR_PTR(
"wf < 1 || hf < 1", __func__, NULL);
516 if (rank < 0.0 || rank > 1.0)
517 return (
PIX *)ERROR_PTR(
"rank must be in [0.0, 1.0]", __func__, NULL);
518 if (wf == 1 && hf == 1)
519 return pixCopy(NULL, pixs);
520 if (scalefactor < 0.2 || scalefactor > 0.7) {
521 L_ERROR(
"invalid scale factor; no scaling used\n", __func__);
525 pix1 = pixScaleAreaMap(pixs, scalefactor, scalefactor);
526 wfs = L_MAX(1, (l_int32)(scalefactor * wf + 0.5));
527 hfs = L_MAX(1, (l_int32)(scalefactor * hf + 0.5));
529 pixGetDimensions(pixs, &w, &h, NULL);
530 pixd = pixScaleToSize(pix2, w, h);
PIX * pixRankFilterWithScaling(PIX *pixs, l_int32 wf, l_int32 hf, l_float32 rank, l_float32 scalefactor)
pixRankFilterWithScaling()