About the kernel of cv2.filter2D
Closed this issue · 2 comments
vinvin0430 commented
I noticed that you used a kernel in demosaicing_mono_float:
kernel = np.array([[1/4, 1/2, 1/4],
[1/2, 1.0, 1/2],
[1/4, 1/2, 1/4]], dtype=np.float64)
img_polarization = cv2.filter2D(img_subsampled, -1, kernel)
What is the role of this kernel?
elerac commented
Hi @vinvin0430!
The kernel
can treat the demosaicing process as the 2D convolution.
Here I show the figure that describes an overview of __demosaicing_mono_float
process.
The main process can be divided into two steps, Subsampling and 2D convolution.
- Subsampling step
Generatesimg_subsampled
by subsampling the values of each channel (angle of polarization filter, 0-45-90-135) ofimg_mpfa
. Forimg_subsampled
, the lattice area shown in the figure contains the same values as inimg_mpfa
and the white area is filled with zeros. - 2D convolution step
After subsampling step, apply 2D convolution toimg_subsampled
. The filterkernel
is designed to calculate the equivalent of demosaicing using bilinear interpolation. As you can see in the figure, the white area is zero, so only a part of the filter (shown in red color) is used for calculation, and the result is the same as general bilinear interpolation demosaicing.
The reason for using 2D convolutional (cv2.filter2D) is that it is easy and fast, thanks to the well-tuned OpenCV code.
vinvin0430 commented
Hi elerac,
Thank you for your patient reply. It helped me a lot. : )