A simple two-way filter can be defined as
Inew (x, y) = Summation (j = yn / 2; j <= y + n / 2) Summation (i = xm / 2; j <= x + m / 2) w (i, j, x, y ) I (I, J)
where a common low-pass filter, such as a Gaussian filter, has a weight w (i, j, x, y) based on the distance from the center of the core (x, y) to each pixel (i, k). For a two-sided filter, the weight is determined based on two distances: the distance between the image space and the distance between the colors.
Simple C implementation below
void convolution(uchar4 *_in, uchar4 *_out, int width, int height, int ~ halfkernelsize, float id, float cd) { int kernelDim = 2*halfkernelsize+1;
for(int y=0; y float sumWeight = 0; unsigned int ctrIdx = y*width + x; float ctrPix[3]; ctrPix[0] = _in[ctrIdx].x; ctrPix[1] = _in[ctrIdx].y; ctrPix[2] = _in[ctrIdx].z;
}
source share