115 const cpl_mask *mask_in,
116 const cpl_size dc_mask_x,
117 const cpl_size dc_mask_y,
118 cpl_image **power_spectrum,
123 cpl_ensure_code(img_in, CPL_ERROR_NULL_INPUT);
125 cpl_ensure_code( dc_mask_x >= 1 && dc_mask_y >= 1
126 && *power_spectrum == NULL, CPL_ERROR_ILLEGAL_INPUT);
129 if (cpl_image_count_rejected(img_in) != 0) {
130 return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
131 "The image can't contain bad pixels");
135 cpl_size nx = cpl_image_get_size_x(img_in);
136 cpl_size ny = cpl_image_get_size_y(img_in);
138 cpl_ensure_code( nx == cpl_mask_get_size_x(mask_in)
139 && ny == cpl_mask_get_size_y(mask_in),
140 CPL_ERROR_INCOMPATIBLE_INPUT);
144 *power_spectrum = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
148 cpl_image *img_in_complex = cpl_image_cast(img_in, CPL_TYPE_DOUBLE_COMPLEX);
149 cpl_image *fft_image = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE_COMPLEX);
150 cpl_fft_image(fft_image, img_in_complex, CPL_FFT_FORWARD);
151 cpl_image_delete(img_in_complex);
154 double complex *fft_image_array = cpl_image_get_data_double_complex(fft_image);
158 double norm_size = nx * ny;
159 for (cpl_size y = 0; y < ny; y++) {
160 for (cpl_size x = 0; x < nx ; x++) {
163 cpl_size idx = (y * nx) + x;
166 double complex value_complex = fft_image_array[idx];
167 double norm_value = creal(value_complex * conj(value_complex)) / norm_size;
170 cpl_image_set(*power_spectrum, x + 1, y + 1, norm_value);
173 cpl_image_delete(fft_image);
177 cpl_mask *out_mask = NULL;
179 out_mask = cpl_mask_duplicate(mask_in);
181 out_mask = cpl_mask_new(nx, ny);
185 for (cpl_size i = 1; i <= dc_mask_x; i++) {
186 for (cpl_size j = 1; j <= dc_mask_y; j++) {
187 cpl_mask_set(out_mask, i, j, CPL_BINARY_1);
190 cpl_image_reject_from_mask(*power_spectrum, out_mask);
193 cpl_mask_delete(out_mask);
197 *std = cpl_image_get_stdev(*power_spectrum);
202 cpl_image_get_mad(*power_spectrum, &mad);
203 *std_mad = CPL_MATH_STD_MAD * mad;
206 return CPL_ERROR_NONE;
cpl_error_code hdrl_fpn_compute(cpl_image *img_in, const cpl_mask *mask_in, const cpl_size dc_mask_x, const cpl_size dc_mask_y, cpl_image **power_spectrum, double *std, double *std_mad)
Algorithms to compute fixed pattern noise on a single image.