I am working on this picture.
Due to its bad quality, firstly I use histogram equalization after that bilateral blur to preserve the edges, adaptive Canny and edge sharpening kernel and the output is this:-
I need the edges to be closed and gone through morphological operations but the results were not satisfactory and the operation can't be generalized on all the images. How to solve this? Here's the code:-
def auto_canny(image, sigma=0.33): # compute the median of the single channel pixel intensities v = np.median(image) # apply automatic Canny edge detection using the computed median lower = int(max(0, (1.0 - sigma) * v)) upper = int(min(255, (1.0 + sigma) * v)) edged = cv2.Canny(image, lower, upper) # return the edged image return edged
def equalize(img): ycrcb = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB) channels = cv2.split(ycrcb) cv2.equalizeHist(channels[0], channels[0]) cv2.merge(channels, ycrcb) cv2.cvtColor(ycrcb, cv2.COLOR_YCR_CB2BGR, img) return img
img = cv2.imread('build1.jpg') imm = equalize(img) sharpen = np.array(([-1, -1, -1], [-1, 9, -1], [-1, -1, -1]), dtype='int') plt.imshow(img) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) blur = cv2.bilateralFilter(img, 9, 75, 75) im = auto_canny(blur) im1 = cv2.filter2D(im, -1, kernel=sharpen)