Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Filtering out coast line

Hi,

In the context of flying over water, I'm trying to segment the coastline out of the water.

To do that I've been using a Canny edge detection, which I'm hoping to use to create several large polygons : Each polygon should be contain either: the coastline, the body of water, or some other occlusion

My problem is that I can't find a way to connect a line to the "borders of the image" and make a polygon that way.

What I currently have produces this image : On the top left, and the right is a coastline (flying over a bay), and the bottom part is the UAV itself with the antenna.

This is almost what I need, but I need to create a polygon that extends all the way to the borders.

image description

This is the code :

def find_coastline(img_gray, img_rgb):
    CANNY_THRSH_LOW = 1000
    CANNY_THRSH_HIGH = 2000
    # add borders for polygons
    #img_gray = cv2.copyMakeBorder(img_gray, 2, 2, 2, 2, cv2.BORDER_CONSTANT, value=0)
    #img_rgb = cv2.copyMakeBorder(img_rgb, 2, 2, 2, 2, cv2.BORDER_CONSTANT, value=0)
    print img_gray.shape
    edge = cv2.Canny(img_gray, CANNY_THRSH_LOW, CANNY_THRSH_HIGH, apertureSize=5)
    kern = np.ones((5, 5))
    # dilatation most of the disparate edges
    edge = cv2.dilate(edge, kern)
    vis = cv2.cvtColor(img_gray, cv2.COLOR_GRAY2BGR)
    vis[edge != 0] = (0, 255, 0)
    cv2.imwrite('boats_canny.jpg', vis)
    # only external contours
    contours, hierarchy = cv2.findContours(edge.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    vis = np.zeros((img_rgb.shape), np.uint8)
    i = 0
    for cnt in contours:
        color = np.random.random_integers(255, size=(3))
        cv2.drawContours( vis, contours0, i, color,
                          3, cv2.CV_AA, hierarchy, 0)
        i += 1
    cv2.imwrite('boats_contours.jpg', vis)

Filtering out coast line

Hi,

In the context of flying over water, I'm trying to segment the coastline out of the water.

To do that I've been using a Canny edge detection, which I'm hoping to use to create several large polygons : Each polygon should be contain either: the coastline, the body of water, or some other occlusion

My problem is that I can't find a way to connect a line to the "borders of the image" and make a polygon that way.

What I currently have produces this image : On the top left, and the right is a coastline (flying over a bay), and the bottom part is the UAV itself with the antenna.

This is almost what I need, but I need to create a polygon that extends all the way to the borders.

image descriptionborders. image description

This is the code :

def find_coastline(img_gray, img_rgb):
    CANNY_THRSH_LOW = 1000
    CANNY_THRSH_HIGH = 2000
    # add borders for polygons
    #img_gray = cv2.copyMakeBorder(img_gray, 2, 2, 2, 2, cv2.BORDER_CONSTANT, value=0)
    #img_rgb = cv2.copyMakeBorder(img_rgb, 2, 2, 2, 2, cv2.BORDER_CONSTANT, value=0)
    print img_gray.shape
    edge = cv2.Canny(img_gray, CANNY_THRSH_LOW, CANNY_THRSH_HIGH, apertureSize=5)
    kern = np.ones((5, 5))
    # dilatation most of the disparate edges
    edge = cv2.dilate(edge, kern)
    vis = cv2.cvtColor(img_gray, cv2.COLOR_GRAY2BGR)
    vis[edge != 0] = (0, 255, 0)
    cv2.imwrite('boats_canny.jpg', vis)
    # only external contours
    contours, hierarchy = cv2.findContours(edge.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    vis = np.zeros((img_rgb.shape), np.uint8)
    i = 0
    for cnt in contours:
        color = np.random.random_integers(255, size=(3))
        cv2.drawContours( vis, contours0, i, color,
                          3, cv2.CV_AA, hierarchy, 0)
        i += 1
    cv2.imwrite('boats_contours.jpg', vis)

Filtering out coast line

Hi,

In the context of flying over water, I'm trying to segment the coastline out of the water.

To do that I've been using a Canny edge detection, which I'm hoping to use to create several large polygons : Each polygon should be contain either: the coastline, the body of water, or some other occlusion

My problem is that I can't find a way to connect a line to the "borders of the image" and make a polygon that way.

What I currently have produces this image : On the top left, and the right is a coastline (flying over a bay), and the bottom part is the UAV itself with the antenna.

This is almost what I need, but I need to create a polygon that extends all the way to the borders. image description

This is the code :

def find_coastline(img_gray, img_rgb):
    CANNY_THRSH_LOW = 1000
    CANNY_THRSH_HIGH = 2000
    # add borders for polygons
    #img_gray = cv2.copyMakeBorder(img_gray, 2, 2, 2, 2, cv2.BORDER_CONSTANT, value=0)
    #img_rgb = cv2.copyMakeBorder(img_rgb, 2, 2, 2, 2, cv2.BORDER_CONSTANT, value=0)
    print img_gray.shape
    edge = cv2.Canny(img_gray, CANNY_THRSH_LOW, CANNY_THRSH_HIGH, apertureSize=5)
    kern = np.ones((5, 5))
    # dilatation most of the disparate edges
    edge = cv2.dilate(edge, kern)
    vis = cv2.cvtColor(img_gray, cv2.COLOR_GRAY2BGR)
    vis[edge != 0] = (0, 255, 0)
    cv2.imwrite('boats_canny.jpg', vis)
    # only external contours
    contours, hierarchy = cv2.findContours(edge.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    vis = np.zeros((img_rgb.shape), np.uint8)
    i = 0
    for cnt in contours:
        color = np.random.random_integers(255, size=(3))
        cv2.drawContours( vis, contours0, i, color,
                          3, cv2.CV_AA, hierarchy, 0)
        i += 1
    cv2.imwrite('boats_contours.jpg', vis)

Filtering out coast line

Hi,

In the context of flying over water, I'm trying to segment the coastline out of the water.

To do that I've been using a Canny edge detection, which I'm hoping to use to create several large polygons : Each polygon should be contain either: the coastline, the body of water, or some other occlusion

My problem is that I can't find a way to connect a line to the "borders of the image" and make a polygon that way.

What I currently have produces this image : On the top left, and the right is a coastline (flying over a bay), and the bottom part is the UAV itself with the antenna.

This is almost what I need, but I need to create a polygon that extends all the way to the borders. image description

This is the code :

def find_coastline(img_gray, img_rgb):
    CANNY_THRSH_LOW = 1000
    CANNY_THRSH_HIGH = 2000
    # add borders for polygons
    edge = cv2.Canny(img_gray, CANNY_THRSH_LOW, CANNY_THRSH_HIGH, apertureSize=5)
    kern = np.ones((5, 5))
    # dilatation connects most of the disparate edges
    edge = cv2.dilate(edge, kern)
    vis = cv2.cvtColor(img_gray, cv2.COLOR_GRAY2BGR)
    vis[edge != 0] = (0, 255, 0)
    cv2.imwrite('boats_canny.jpg', vis)
    # only external contours
    contours, hierarchy = cv2.findContours(edge.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    vis = np.zeros((img_rgb.shape), np.uint8)
    i = 0
    for cnt in contours:
        color = np.random.random_integers(255, size=(3))
        cv2.drawContours( vis, contours0, i, color,
                          3, cv2.CV_AA, hierarchy, 0)
        i += 1
    cv2.imwrite('boats_contours.jpg', vis)

Filtering out coast line

Hi,

In the context of flying over water, I'm trying to segment the coastline out of the water.

To do that I've been using a Canny edge detection, which I'm hoping to use to create several large polygons : Each polygon should be contain either: the coastline, the body of water, or some other occlusion

My problem is that I can't find a way to connect a line to the "borders of the image" and make a polygon that way.

What I currently have produces this image : On the top left, and the right is a coastline (flying over a bay), and the bottom part is the UAV itself with the antenna.

This is almost what I need, but I need to create a polygon that extends all the way to the borders. image description

This is the code :

def find_coastline(img_gray, img_rgb):
    CANNY_THRSH_LOW = 1000
    CANNY_THRSH_HIGH = 2000
    # add borders for polygons
    edge = cv2.Canny(img_gray, CANNY_THRSH_LOW, CANNY_THRSH_HIGH, apertureSize=5)
    kern = np.ones((5, 5))
    # dilatation connects most of the disparate edges
    edge = cv2.dilate(edge, kern)
    vis = cv2.cvtColor(img_gray, cv2.COLOR_GRAY2BGR)
    vis[edge != 0] = (0, 255, 0)
    cv2.imwrite('boats_canny.jpg', vis)
    # only external contours
    contours, hierarchy = cv2.findContours(edge.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    vis = np.zeros((img_rgb.shape), np.uint8)
    i = 0
    for cnt in contours:
        color = np.random.random_integers(255, size=(3))
        cv2.drawContours( vis, contours0, i, color,
                          3, cv2.CV_AA, hierarchy, 0)
        i += 1
    cv2.imwrite('boats_contours.jpg', vis)

This is the original image : image description