I need to build an LoG filer using only my method and only matplotlib OpenCV and NumPy (but not build-in functions that do the filter just to help calculate)
def edgeDetectionZeroCrossingLOG(img: np.ndarray) -> (np.ndarray):
"""
Detecting edges using the "ZeroCrossingLOG" method
:param I: Input image
:return: :return: Edge matrix
"""
kernel = np.ndarray((3, 3))
b_img = blurImage1(img, kernel)
k = np.array([[0, 1, 0],
[1, -4, 1],
[0, 1, 0]])
img_dervative = conv2D(img, k)
***Zero-Crossing***
Steps:
- use a Gaussian filter to blur the image
def blurImage1(in_image: np.ndarray, kernel_size: np.ndarray) -> np.ndarray:
"""
Blur an image using a Gaussian kernel
:param inImage: Input image
:param kernelSize: Kernel size
:return: The Blurred image
"""
gaussian = np.ndarray(kernel_size)
sigma = 0.3 * ((kernel_size[0] - 1) * 0.5 - 1) + 0.8
for x in range(0, kernel_size[0]):
for y in range(0, kernel_size[1]):
gaussian[x, y] = math.exp(-((x ** 2 + y ** 2) / (2.0 * sigma ** 2))) / (math.pi * (sigma ** 2) * 2)
return conv2D(in_image, gaussian)
- Use derivation Laplacian kernel Ix,Iy
k = np.array([[0, 1, 0],
[1, -4, 1],
[0, 1, 0]])
- Need to find all the "zero-crossing" in the 2D array of the image and marke them as one's and the rest zero's
My main problem is the zero crossings, I cannot find a way to do it.
I need to check all the crossings without a threshold -> { (-+),(+-),(-0+),(+0-)}
, and for every crossing to make as 1 and the rest leave at zero.
( The convolution is also implemented by me the function conv2D)