40 #include <cpl_matrix.h>
42 #include "hawki_mask.h"
58 const cpl_matrix * ker)
61 const double * ker_arr;
64 int curr_pos, im_pos, filt_pos;
70 cpl_binary * out_data;
73 cpl_ensure_code(in && ker, CPL_ERROR_NULL_INPUT);
76 nr = cpl_matrix_get_nrow(ker);
77 nc = cpl_matrix_get_ncol(ker);
78 ker_arr = cpl_matrix_get_data_const(ker);
81 cpl_ensure_code(nc%2 && nr%2, CPL_ERROR_ILLEGAL_INPUT);
82 cpl_ensure_code(nc<=31 && nr<=31, CPL_ERROR_ILLEGAL_INPUT);
89 nx = cpl_mask_get_size_x(in);
90 ny = cpl_mask_get_size_y(in);
91 out = cpl_mask_new(nx, ny);
92 in_data = cpl_mask_get_data(in);
93 out_data = cpl_mask_get_data(out);
96 for (j=0; j<ny; j++) {
97 for (i=0; i<nx; i++) {
101 if ((i<hsx) || (i>=nx-hsx) || (j<hsy) || (j>=ny-hsy)) {
102 (out_data)[curr_pos] = CPL_BINARY_0;
105 (out_data)[curr_pos] = CPL_BINARY_0;
107 im_pos = curr_pos - hsx + hsy*nx;
110 for (k=0; k<nr; k++) {
111 for (l=0; l<nc; l++) {
112 if (((in_data)[im_pos] == CPL_BINARY_1) &&
113 (fabs(ker_arr[filt_pos]) > FLT_MIN))
114 sum+=fabs(ker_arr[filt_pos]);
123 (out_data)[curr_pos] = CPL_BINARY_1;
127 memcpy(in_data, out_data, nx * ny *
sizeof(cpl_binary));
128 cpl_mask_delete(out);
129 return CPL_ERROR_NONE;