// TODO L_THRESH_NEG_TO_BLACK static hc_dpix_t *hcApplyFilter( hc_dpix_t *src, hc_dpix_t *filter ) { uint32_t w, h; uint32_t i, j, k; fftw_complex *output; double *data; hc_dpix_t *dpixd; if (!src && !filter) { ERROR("src or filter not defined"); return(NULL); } w=src->width; h=src->height; if (filter->width > w / 2 + 1 || filter->height > h) { ERROR("filter is smaller than source"); return(NULL); } /* Calculate the DFT of pixs */ // TODO was with L_WITH_SHIFTING, does it make a difference? if (NULL == (output = dpixDFT( src ))) { ERROR("src DFT not computed"); return(NULL); } /* Filter the DFT results */ data = filter->data; for (i = 0, k = 0; i < h; i++) { for (j = 0; j < w / 2 + 1; j++, k++) { output[k] *= (*data); data++; } } /* Compute the inverse of the DFT */ dpixd = dpixInverseDFT(output, w, h ); /* Release the allocated resources */ fftw_free(output); return dpixd; }
/*! * pixInverseDFT() * * Input: dft * w, h (image size) * shiftflag (L_NO_SHIFTING or L_WITH_SHIFTING) * outflag (L_CLIP_TO_ZERO, L_TAKE_ABSVAL, * L_THRESH_NEG_TO_BLACK or L_THRESH_NEG_TO_WHITE) * Return: pixd (8bpp), or null on error * * Notes: * (1) Set @shiftflag to L_WITH_SHIFTING if the DC was moved to the * center of the image during the DFT computation. Reshifting it * will move the DC back to the top left corner (0, 0). * (2) It is the responsibility of the caller to release the allocated * complex array by invoking fftw_free(). */ PIX * pixInverseDFT(fftw_complex *dft, l_int32 w, l_int32 h, l_int32 shiftflag, l_int32 outflag) { PIX *pixd; DPIX *dpix; PROCNAME("pixInverseDFT"); dpix = dpixInverseDFT(dft, w, h); /* Convert DPix to a Pix */ pixd = dpixConvertToPix(dpix, 8, outflag, 0, shiftflag); dpixDestroy(&dpix); return pixd; }