Home > Back-end >  image processing, get pure edges
image processing, get pure edges

Time:05-27

I am a beginner in python programming and I am asking for some tips. I have a diagram by which I would like to detect edges and then filter to get only clean edges. Can anyone help how I can write python code to go through the rest of the diagram? I used a Sobel filter for edge detection, but I don't know how to approach a median filter with neighborhood

enter image description here

pxq with the condition p >> q and p << q.

Here is my code in python:

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('original_image.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ddepth = -1

sobelX = cv2.Sobel(img, ddepth ,1, 0, ksize=3,borderType=cv2.BORDER_DEFAULT)

sobelY = cv2.Sobel(img, ddepth, 0, 1, ksize=3,borderType=cv2.BORDER_DEFAULT)

mag = np.hypot(sobelX, sobelY)

mag = mag / mag.max() * 255

mag = np.uint8(mag)

theta = np.arctan2(sobelY, sobelX)

angle = np.rad2deg(theta)

I don't understand the next step:

Apply median filter with neighborhood pxq (p>>q) and (p<<q)

Can someone explain to me in a simple way?

CodePudding user response:

I presume your professor is trying to differentiate between horizontal and vertical edges but hasn't explained it too clearly.

If I start with this image, and ignore the Sobel stuff since it is already effectively edges:

enter image description here

from skimage.filters.rank import median
import cv2

# Load image and greyscale it
im = cv2.imread('radial.png', cv2.IMREAD_GRAYSCALE)

# Define a 25x1 and a 1x25 footprint for the median function
footprintA = np.ones((1,25), np.uint8)
footprintB = footprintA.reshape(-1,1)

# Apply each to image
resA = median(im, footprintA)
resB = median(im, footprintB)

enter image description here

enter image description here


Here is a little animation showing the effect of the footprint shape:

enter image description here


I used scikit-image because I don't know how you make a non-square footprint with OpenCV.

CodePudding user response:

I think it means the median filter with non-square kernel. In OpenCV median filtering

  • Related