From 641d222fe2fb6a3086ceba503505cdc50f60de29 Mon Sep 17 00:00:00 2001 From: Christian <s224389@dtu.dk> Date: Tue, 14 Jan 2025 15:37:54 +0100 Subject: [PATCH] Added feature increasing contrast before creating cost image --- live_wire.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/live_wire.py b/live_wire.py index 4f8c86f..a0b2694 100644 --- a/live_wire.py +++ b/live_wire.py @@ -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 -- GitLab