Skip to content
Snippets Groups Projects

Live wire to be implemented into GUI

Merged s224389 requested to merge live_wire into GUI
1 file
+ 15
6
Compare changes
  • Side-by-side
  • Inline
+ 15
6
@@ -2,7 +2,7 @@ import time
import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage import exposure
from skimage.filters import gaussian
from skimage.feature import canny
from skimage.graph import route_through_array
@@ -59,9 +59,19 @@ def compute_cost(image, sigma=3.0, epsilon=1e-5):
"""
Smooth the image, run Canny edge detection, then invert the edge map into a cost image.
"""
smoothed_img = gaussian(image, sigma=sigma)
# Apply histogram equalization
image_contrasted = exposure.equalize_adapthist(image, clip_limit=0.01)
# Apply smoothing
smoothed_img = gaussian(image_contrasted, sigma=sigma)
# Apply Canny edge detection
canny_img = canny(smoothed_img)
# Create cost image
cost_img = 1.0 / (canny_img + epsilon) # Invert edges: higher cost where edges are stronger
return cost_img, canny_img
def backtrack_pixels_on_image(img_color, path_coords, bgr_color=(0, 0, 255)):
@@ -74,13 +84,12 @@ def backtrack_pixels_on_image(img_color, path_coords, bgr_color=(0, 0, 255)):
return img_color
#### Main Script ####
def main():
# Define input parameters
image_path = './tests/slice_60_volQ.png'
image_path = 'bipes_slice.png'
image_type = 'gray' # 'gray' or 'color'
downscale_factor = 100 # % of original size
points_path = './tests/LiveWireEndPoints.npy'
points_path = 'bipesPoints.npy'
# Load image
image = load_image(image_path, image_type)
@@ -132,4 +141,4 @@ def main():
plt.show()
if __name__ == "__main__":
main()
main()
\ No newline at end of file
Loading