code that finds the edges of a white object in a binary image and uses the houghlines to plot the boundary on the colour image in python

You can use the OpenCV library in Python to achieve this task. Here is an example code that does the following:

  1. Reads the input binary image and color image.
  2. Applies Canny edge detection to the binary image to obtain the edges.
  3. Applies HoughLine transform to the edges to obtain the lines representing the boundaries of the object.
  4. Draws the lines on the color image.
main.py
import cv2
import numpy as np

# Read input images
binary_image = cv2.imread('binary_image.png', cv2.IMREAD_GRAYSCALE)
color_image = cv2.imread('color_image.jpg')

# Apply Canny edge detection to binary image
edges = cv2.Canny(binary_image, 100, 200)

# Apply HoughLine transform to edges
lines = cv2.HoughLines(edges, 1, np.pi/180, 200)

# Draw lines on color image
if lines is not None:
    for line in lines:
        rho, theta = line[0]
        a = np.cos(theta)
        b = np.sin(theta)
        x0 = a*rho
        y0 = b*rho
        x1 = int(x0 + 1000*(-b))
        y1 = int(y0 + 1000*(a))
        x2 = int(x0 - 1000*(-b))
        y2 = int(y0 - 1000*(a))
        cv2.line(color_image, (x1,y1), (x2,y2), (0,255,0), 2)

# Show output image
cv2.imshow('Output Image', color_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
823 chars
32 lines

Note that you may need to adjust the parameters of Canny edge detection and HoughLine transform for your specific image.

gistlibby LogSnag