Skip to content
Snippets Groups Projects
Commit 641d222f authored by Christian's avatar Christian
Browse files

Added feature increasing contrast before creating cost image

parent 5d292d48
No related branches found
No related tags found
1 merge request!3Live wire to be implemented into GUI
...@@ -2,7 +2,7 @@ import time ...@@ -2,7 +2,7 @@ import time
import cv2 import cv2
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from skimage import exposure
from skimage.filters import gaussian from skimage.filters import gaussian
from skimage.feature import canny from skimage.feature import canny
from skimage.graph import route_through_array from skimage.graph import route_through_array
...@@ -59,9 +59,19 @@ def compute_cost(image, sigma=3.0, epsilon=1e-5): ...@@ -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. 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) canny_img = canny(smoothed_img)
# Create cost image
cost_img = 1.0 / (canny_img + epsilon) # Invert edges: higher cost where edges are stronger cost_img = 1.0 / (canny_img + epsilon) # Invert edges: higher cost where edges are stronger
return cost_img, canny_img return cost_img, canny_img
def backtrack_pixels_on_image(img_color, path_coords, bgr_color=(0, 0, 255)): 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)): ...@@ -74,13 +84,12 @@ def backtrack_pixels_on_image(img_color, path_coords, bgr_color=(0, 0, 255)):
return img_color return img_color
#### Main Script #### #### Main Script ####
def main(): def main():
# Define input parameters # Define input parameters
image_path = './tests/slice_60_volQ.png' image_path = 'bipes_slice.png'
image_type = 'gray' # 'gray' or 'color' image_type = 'gray' # 'gray' or 'color'
downscale_factor = 100 # % of original size downscale_factor = 100 # % of original size
points_path = './tests/LiveWireEndPoints.npy' points_path = 'bipesPoints.npy'
# Load image # Load image
image = load_image(image_path, image_type) image = load_image(image_path, image_type)
...@@ -132,4 +141,4 @@ def main(): ...@@ -132,4 +141,4 @@ def main():
plt.show() plt.show()
if __name__ == "__main__": if __name__ == "__main__":
main() main()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment