VC-filter is a new high-quality edge detector based on the Visual Cortex study
Project description
VC FILTER
VC filter is a new high-quality edge detector based on the Visual Cortex study
Installation
pip install vc-filter
About VC filter
The 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, 1
0, 0, 0
-1, -2, -1
There 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 that orientation-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:
from pathlib import Path
import vc_filter
def opencv_recommended_filter(image):
"""
https://docs.opencv.org/3.4/d5/db5/tutorial_laplace_operator.html
"""
# Remove noise by blurring with a Gaussian filter
image_gauss = cv.GaussianBlur(image, (3, 3), cv.BORDER_DEFAULT)
# Convert the image to grayscale
image_in_gray = cv.cvtColor(image_gauss, cv.COLOR_BGR2GRAY)
# Apply Laplace function
image_out_gray = cv.Laplacian(image_in_gray, cv.CV_16S, ksize=3)
# converting back to uint8
abs_image_out_gray = cv.convertScaleAbs(image_out_gray)
return abs_image_out_gray
def contrast_enhancement(image, contrast_param):
image_contrast = image * contrast_param
image_contrast[image_contrast > 255] = 255
return image_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)
# -------------------------------------------------------------
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file vc_filter-1.1.20.tar.gz
.
File metadata
- Download URL: vc_filter-1.1.20.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.11 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e628682b40c7a461417d1e925b7b10ac3693a3a80e02775a3ba7aaaac7d8d6c |
|
MD5 | ad64e8c61a2c625c9f1bdcc28b059bb6 |
|
BLAKE2b-256 | e3260a820b549db5772b547a174486f711a187481971b1ed40b951797b3ea969 |
File details
Details for the file vc_filter-1.1.20-py3-none-any.whl
.
File metadata
- Download URL: vc_filter-1.1.20-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.11 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bb37008132d615754a78e0d1dc231ca23adc04ff7507533018fdba232a576ac |
|
MD5 | 79922a73b47e5457da4442ccde3fe511 |
|
BLAKE2b-256 | d13b371f4f96275206c011914b4afc4a1082bdc141840d1ffd83205ef92523d1 |