Package: vc-filter
VC FILTERVC filter is a new high-quality edge detector based on the Visual Cortex studyInstallationpip install vc-filterAbout VC filterThe well-known Sobel filter with the kernel shown below is “tuned” to detect horizontal edges.
As the deviation from the horizontal increases, the filter’s sensitivity falls, and as a result,
the vertical edges become invisible (image in the center). In other words, they all hide in the
"blind zone" of the filter.1,2,10,0,0-1,-2,-1There are two ways to perform Sobel filtering:Spatial domain:filtering is done by convolving the image with a Sobel kernel.
OpenCV has a ready-made solution for this -cv2.Sobel(image, cv.CV_64F, 0, 1, ksize=3).Frequency domain:multiplying Fourier transform of an image with Fourier transform of Sobel kernel,
and compute inverse Fourier transform of the resulting product:We propose to upgrade the procedure above as follows:Here rot(b, alpha) denotes rotation of the kernel spectrum by angle alpha.
This rotation changes the position of the blind zone. Unfortunately, neither the Sobel filter
nor its modifications can spare us from blind zones. However,a set of modified Sobel filters
acting parallel(vc-filter) may succeed. So, let’s use a set of filters with angles equal
to 0 degrees, 12 degrees, 24 degrees, etc. And lastly, we sum up the filters' results and get
a perfect outline image (top right image).The use of the vc-filter is straightforward. Unlike all known filters, the vc-filter has no parameters.
However, the outline image obtained by vc-filter usually requires some simple contrast enhancement.Where else can we find edge detectors tuned to different angles? D.Huebel and T.Wiesel discovered such
detectors (orientation-selective neurons) in the visual cortex over 60 years ago, but their role
is still unclear. We guess thatorientation-selective neurons compose outline image of
the visible object in the same way as the set of modified Sobel filters in our method.How to use:frompathlibimportPathimportvc_filterdefopencv_recommended_filter(image):"""https://docs.opencv.org/3.4/d5/db5/tutorial_laplace_operator.html"""# Remove noise by blurring with a Gaussian filterimage_gauss=cv.GaussianBlur(image,(3,3),cv.BORDER_DEFAULT)# Convert the image to grayscaleimage_in_gray=cv.cvtColor(image_gauss,cv.COLOR_BGR2GRAY)# Apply Laplace functionimage_out_gray=cv.Laplacian(image_in_gray,cv.CV_16S,ksize=3)# converting back to uint8abs_image_out_gray=cv.convertScaleAbs(image_out_gray)returnabs_image_out_graydefcontrast_enhancement(image,contrast_param):image_contrast=image*contrast_paramimage_contrast[image_contrast>255]=255returnimage_contrast""" Get input image """path_in=Path.cwd()/'DATA'/'image_in.png'image_in=cv.imread(str(path_in),cv.IMREAD_UNCHANGED)""" OpenCV recommended filter """# -------------------------------------------------------------edges_opencv=opencv_recommended_filter(image_in)path_opencv=Path.cwd()/'DATA'/'edges_opencv.png'cv.imwrite(str(path_opencv),edges_opencv)# -------------------------------------------------------------""" VC filter """# -------------------------------------------------------------edges_vcf=vc_filter.apply(image_in)edges_vcf_enh=contrast_enhancement(edges_vcf,1.7)path_vcf_enh=Path.cwd()/'DATA'/'edges_vcf_enh.png'cv.imwrite(str(path_vcf_enh),edges_vcf_enh)# -------------------------------------------------------------