In short: take an image of a graph structure; how can we isolate the segments/edges and do some computations on them?
I am working on 3d printed Voronoi filters, trying to detect defects in their printing, and a possible defect is a “too thick” edge, as in the following image
3d printed Voronoi filter
In that case, for example, there is a too big edge, which I could find by computing the thickness of all segments and seeing that measurement as an outlier.
For now I tried several approaches. I tried with computing a distance matrix to detect big chunks of consecutive white points, roughly speaking. This works but the junction points in which the edges meet cover the result.
first method
The code was:
import cv2
import numpy as np
from matplotlib import pyplot as plt
# Load the image
pid = np.random.randint(0,79) # part-id
image_path = generate_image_path(part_id)
image = cv2.imread(image_path)
# grayscale conversion
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# binarization
(T, binary_image) = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
# apply distance transform
dist_transform = cv2.distanceTransform(binary_image, cv2.DIST_L2, cv2.DIST_MASK_5)
# create a circular mask
h, w = binary_image.shape
center = (w // 2, h // 2)
radius = min(center[0], center[1], w - center[0], h - center[1])-20
mask = np.zeros((h, w), dtype=np.uint8)
cv2.circle(mask, center, radius, 1, thickness=-1)
# Apply the mask to the distance transform
# masked_dist_transform = dist_transform * mask
binary_image = binary_image * mask
masked_dist_transform = cv2.distanceTransform(binary_image, cv2.DIST_C, cv2.DIST_MASK_3)
# Find the maximum thickness
max_thickness = np.max(masked_dist_transform)
So I tried to firstly remove the junction points, by fitting some circles on the image, but with no good result, probably due to the complexity of the coding.
fedem is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.