Ejemplo n.º 1
0
def detect_edges(imlist, out_dir):
    for imname in tqdm(imlist):
        I = cv2.imread(os.path.join(IMAGE_DIR, str(imname) + '.jpg'))
        gimg = cv2.cvtColor(I, cv2.COLOR_BGR2GRAY)

        print('Bilateral filtering...\n')
        gimg = bilatfilt(gimg, 21, 3, 10)

        angles = [0, 45, 90, 135]
        nang = len(angles)

        print('Calculating Gradient...\n')
        img_edges = get_edges(gimg, 2, nang, angles)

        for n in range(nang):
            img_edges[n, :, :] = nonmaxsup(img_edges[n, :, :], angles[n])
        print('after nms: ', np.max(img_edges))
        img_edge = np.max(img_edges, axis=0)
        lim = np.uint8(np.max(img_edge))

        print('Calculating Threshold...\n')
        th = get_threshold(gimg)
        the = get_threshold(img_edge)

        print('\nThresholding...\n')
        img_edge = threshold(img_edge, the * 0.25)

        print('Applying Hysteresis...\n')
        img_edge = nonmaxsup(hysteresis(img_edge), 90)

        out_file_name = os.path.join(out_dir, str(imname) + '.png')
        cv2.imwrite(out_file_name, img_edge)
Ejemplo n.º 2
0
                    Ipad[i, j] = 255
                else:
                    Ipad[i, j] = 0
    Ih = Ipad[1:r + 1, 1:c + 1]
    return Ih


#...........................................................................................
#Reading the image
img = cv2.imread('108073.jpg')
gimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
dim = img.shape
#...........................................................................................
#Bilateral filtering
print 'Bilateral filtering...\n'
gimg = bilatfilt(gimg, 5, 3, 10)
print 'after bilat: ', np.max(gimg), '\n'
#...........................................................................................
stime = time.time()
angles = [0, 45, 90, 135]
nang = len(angles)
#...........................................................................................
#Gradient of Image
print 'Calculating Gradient...\n'
img_edges = get_edges(gimg, 2)
print 'after gradient: ', np.max(img_edges), '\n'
#for i in xrange(nang):
#	img_edges[i,:,:] = img_edges[i,:,:]*255/np.max(img_edges[i,:,:])
#...........................................................................................
#Non-max suppression
print 'Suppressing Non-maximas...\n'