Mask Edge detected Images


This Content is from Stack Overflow. Question asked by Abdullah

Hi All I am new to image processing and I was developing a code to detect cracks within an image. The purpose of the code is to build a machine learning algorithm to help detecting and quantifying cracks within an image. The images attached below shows the image before and after processing. I have been trying to mask the area between the edges using morphology for visualizing and quantifying purposes based on total area of masked image but it is not doing the job as some of the major cracks are left unmasked after applying the morphology transformation. Hope if someone can help me with this. The code used is also shown here.

# importing necessary libraries
import numpy as np
import cv2
from matplotlib import pyplot as plt

# read a cracked sample image
img = cv2.imread('Input-Set/Original.tif')

# Convert into gray scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Image processing ( smoothing )
# Averaging
blur = cv2.blur(gray,(3,3))

# Apply logarithmic transform
img_log = (np.log(blur+1)/(np.log(1+np.max(blur))))*255
# Specify the data type
img_log = np.array(img_log,dtype=np.uint8)

# Image smoothing: bilateral filter
bilateral = cv2.bilateralFilter(img_log, 5, 75, 75)

# Canny Edge Detection
edges = cv2.Canny(bilateral,20,20)

# Morphological Closing Operator
kernel = np.ones((10,10),np.uint8)
closing = cv2.morphologyEx(edges, cv2.MORPH_CLOSE, kernel)

# Create feature detecting method
orb = cv2.ORB_create(nfeatures=1500)

# Make featured Image
keypoints, descriptors = orb.detectAndCompute(closing, None)
featuredImg = cv2.drawKeypoints(closing, keypoints, None)

# Create an output image
cv2.imwrite('Output-Set/Edges.tif', edges)
cv2.imwrite('Output-Set/Morphology.tif', closing)

Original Edges Morphology


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?