예제 #1
0
파일: training.py 프로젝트: sssruhan1/xray
def generate_blur_canny_subfolders(folder, outputFolder):
    from src.utils.canny import my_canny
    from src.utils.canny import best_edges

    from src.utils.io import filename2arr
    from src.utils.io import saveimage_pil
    import os
    for dirName, subdirList, fileList in os.walk(folder):
        for subdir  in subdirList:
           for dirName2, subdirList2, fileList in os.walk(dirName + '/' +subdir):
               for filename in fileList:
                   parts = filename.split('.')
                   if parts[0] == '':
                       continue
                   arr = filename2arr(dirName2 + '/' + filename)
                   ret = best_edges(arr)
                   if not os.path.exists(outputFolder + '/' + subdir):
                        os.makedirs(outputFolder + '/' + subdir)
                   outfn = outputFolder + '/' + subdir + '/'+ parts[0] + '.jpg'
                   print "saving canny file " + outfn
                   saveimage_pil(255 * ret.astype('uint8'), outfn, show=False)
예제 #2
0
    halves = pickle.load(open(fn, "rb"))
    halves = non_max_suppression_merge(halves, overlapThresh=0)
    if halves is not None:
        # 1. detect ROI
        bbox = get_huge_bounding_box(halves)

        img1 = Image.fromarray(arr)
        # fn = result_dir + '/' + testn + '_half_boxes.pkl'
        # pickle.dump(halves, open(fn, "wb"))
        img1=add_boxes(halves, img1)
        img1.show()
        img1.save(result_dir +'/' + testn +'_half_boxes.jpg')

        # 2. detect edges
        ROI = arr[bbox[1]: bbox[3], bbox[0]: bbox[2]]
        edges, sigma, cur_ROI= best_edges(ROI, threshold=0.02)
        showimage_pil(edges)


        # ## 3. using hough_transform to find initial horizontal line
        #
        # from src.utils.hough import hough_horizontal
        # fn = result_dir + '/' + testn  + 'canny_hough'
        # img2 = Image.fromarray(ROI)
        # lines_init, _ = hough_horizontal(edges, fn, hough_line_len=30, line_gap=40, save=True, show=True, raw=img2, xdiff=0, ydiff=0)
        #
        #
        # ## 4. Extend line using smaller sigma
        # from src.utils.util import extend_line_canny_points
        # from src.utils.canny import my_canny
        # fn = fn = result_dir + '/' + testn  + 'canny_extend'