I'm working on inserting guided selection tool (foreground extraction) into Krita, just need a little guidance

From what I understand so far, guided selection involves box filtering which is basically pixel becomes the average of surrounding pixel including itself. I’m using this link to understand more about what it is (I use a few more resources, but this is the clearest to me).

It appears that zeros() can be seen as average(), so correct me on that if I’m not mistaken. On variance, it looks to me from the code that it calculates the variance using kernel mean rather than the entire image.

Sum to me over each window seem to be adding all of the values within vectors.

Cross term isn’t all that clear. This is something I would like more explanation on.

Padding likely has to do with out-of-bound convolution operation. Am I right on that?

EDIT: I forgot to mention I already have the box convolution code done, and doing the variance convolution.


EDIT: This is what cross-term means, right? → How to Measure the Covariance and Correlation of Data Samples - dummies

The best way to understand the guided filter is to read the original paper (or thesis) and code the authors provided. File Exchange usually contains ripped off material. Your example is evident of that. The uploader asks for credit when the code clearly states it is an implementation from Canon(?) with a citation of the paper. If you are looking for implementation examples, look no further than CImg, RT, dt and PF.

Yes, the basis of the guided filter is the box filter, which is for localizing the filter to a window neighbourhood (kernel). From there, you build other components such as the covariance and correlation. These parts make up a weighting component that controls the regularization of the filter so that the smoothing isn’t equal everywhere like the Gaussian.

The rest is just MATLAB. zeros prepares the window size and padding accounts for boundary conditions.

1 Like

I wasn’t really understanding the paper, but I did found the code to be easier to understand. I think that I have managed to have a great start as I already have programmed the box filter.

The next part on my work is figuring out how to work with multiple images using c++ and variables in context of Krita.