@@ -95,6 +95,10 @@ static PyObject *fmedian(PyObject *self, PyObject *args)
9595 return NULL ;
9696 }
9797
98+ /* Convert from full window size to half-size for internal use */
99+ int xsize_half = xsize / 2 ;
100+ int ysize_half = ysize / 2 ;
101+
98102 /* Check input arguments */
99103 if (check_inputs (input_array , output_array , & height , & width ) != 0 )
100104 {
@@ -110,7 +114,7 @@ static PyObject *fmedian(PyObject *self, PyObject *args)
110114 npy_intp * output_strides = PyArray_STRIDES (output_array );
111115
112116 /* Allocate buffer for neighborhood values */
113- int max_neighbors = (2 * xsize + 1 ) * (2 * ysize + 1 );
117+ int max_neighbors = (2 * xsize_half + 1 ) * (2 * ysize_half + 1 );
114118 double * neighbors = (double * )malloc (max_neighbors * sizeof (double ));
115119 if (neighbors == NULL )
116120 {
@@ -129,9 +133,9 @@ static PyObject *fmedian(PyObject *self, PyObject *args)
129133 double center_value = * (double * )(((char * )input_data ) + y * input_strides [0 ] + x * input_strides [1 ]);
130134
131135 /* Collect neighborhood values (conditionally include center) */
132- for (int dy = - ysize ; dy <= ysize ; dy ++ )
136+ for (int dy = - ysize_half ; dy <= ysize_half ; dy ++ )
133137 {
134- for (int dx = - xsize ; dx <= xsize ; dx ++ )
138+ for (int dx = - xsize_half ; dx <= xsize_half ; dx ++ )
135139 {
136140 int ny = y + dy ;
137141 int nx = x + dx ;
@@ -197,9 +201,9 @@ static PyMethodDef FmedianMethods[] = {
197201 " output_array : numpy.ndarray (float64, 2D)\n"
198202 " Output array (same size as input)\n"
199203 " xsize : int\n"
200- " Half- width of window in x direction\n"
204+ " Full width of window in x direction\n"
201205 " ysize : int\n"
202- " Half-width of window in y direction\n"
206+ " Full height of window in y direction\n"
203207 " exclude_center : int\n"
204208 " If non-zero, exclude the center pixel from the median calculation\n" },
205209 {NULL , NULL , 0 , NULL }};
0 commit comments