I'm trying to create a filter that uses vectors as coefficients.
A typical kernel used in imfilter
looks like:
0 1 0
1 -4 1
0 1 0
Where each element is a scalar, and the filtering basically takes all windows of 3x3 of the image (MxN), multiplies the pixel values by the matching coefficients and sums all products to place the output pixel.
I would like to extend this, so that each element in the kernel is not a scalar, but actually a vector (Px1). This makes the kernel something like 3x3xP. The rest of the functionality should be the same: Multiply the coefficient (vector) by the image pixel (scalar * vector), sum all products (sum of vectors of same dimensions), and the output matrix should have the dimensions of (MxNxP).
I know that imfilter
doesn't support that and produces a result of (MxN).
Is there another Matlab function that does this, or do I need to implement from scratch?
Some comments: The image is usually logical (0 or 1), and some of the filter elements can be zero, and not contribute to the sum.