Esempio n. 1
0
def regionSetToBoxes(regionsSet,
                     overlapThresh,
                     sizeRange=[0, 440 * 440],
                     isVisualize=False):
    bboxList = []
    for region in regionsSet:
        for region_i in region[0]:
            r = region_i[1]
            y = r[0]
            x = r[1]
            h = r[2] - y
            w = r[3] - x
            if (w * h < sizeRange[1]) and (w * h > sizeRange[0]):
                bboxList.append([y, x, h, w])
                if isVisualize:
                    regionMap = region[1]
                    regionLabels = region_i[2]
                    pseudoMap = np.zeros((440, 440))
                    for label in regionLabels:
                        pseudoMap[np.where(regionMap == label)] = 255
                    plf.showGrid(pseudoMap, [[y, x, h, w]])
                    plt.show()
    bboxes = np.array(bboxList)
    keepBoxes = filterOverlap(bboxes, overlapThresh)
    keepBoxes = np.array(keepBoxes)
    # convert [y1, x1, h, w] to [y1, x1, y2, x2]
    keepBoxes[:, 2] = keepBoxes[:, 0] + keepBoxes[:, 2]
    keepBoxes[:, 3] = keepBoxes[:, 1] + keepBoxes[:, 3]
    # convert [y1, x1, y2, x2] to [x1, y1, x2, y2]
    keepBoxes[:, [0, 1]] = keepBoxes[:, [1, 0]]
    keepBoxes[:, [2, 3]] = keepBoxes[:, [3, 2]]
    return keepBoxes
def show_region_patch_grid(imgFile,
                           F0,
                           region_patch_list,
                           alpha,
                           eraseMap,
                           saveFolder=None):
    img = skimage.io.imread(imgFile)
    if len(img.shape) == 2:
        img = skimage.color.gray2rgb(img)
    n_region = len(set(list(F0.flatten())))
    eraseLabels = set(list(F0[numpy.where(eraseMap == 1)].flatten()))
    colors = numpy.random.randint(0, 255, (n_region, 3))
    for e in eraseLabels:
        colors[e] = 0
    color_regions = colors[F0]
    result = (color_regions * alpha + img * (1. - alpha)).astype(numpy.uint8)
    if saveFolder is not None:
        imName = imgFile[-20:-4]
        ii = 1
    for l in region_patch_list:
        if len(l) != 0:
            plf.showGrid(result, l)
            if saveFolder is not None:
                plt.savefig(saveFolder + imName + '_subregion' + str(ii) +
                            '.jpg')
                ii += 1

    # plt.imshow(result)
    plt.show()
Esempio n. 3
0
        #
        # l_s = np.array(labels_special).reshape(b_s.shape[0], 1)
        # l_c = np.array(labels_common).reshape(b_c.shape[0], 1)
        # print l_s.shape
        #
        # bb = np.zeros((0, 4), dtype='i')
        # ll = np.zeros((0, 1), dtype='i')
        # if b_s.shape[0] != 0:
        #     bb = np.vstack([bb, b_s])
        #     ll = np.vstack([ll, l_s])
        # if b_c.shape[0] != 0:
        #     ll = np.vstack([ll, l_c])
        #     bb = np.vstack([bb, b_c])
        # print b_s
        # print b_c
        # print bb
        # print l_s
        # print l_c
        # print ll
        im = imread(imgFile)
        im_s = rotate(im, angle_special)
        bbox_s = list(bbox_special)
        bbox_c = list(bbox_common)
        plf.showGrid(im_s, bbox_s)
        print imgName
        plt.title(imgName + '_special')
        im_c = rotate(im, angle_common)
        plf.showGrid(im_c, bbox_c)
        plt.title(imgName + '_common')

        plt.show()
Esempio n. 4
0
    paras['imgFile'] = imgFile
    im = skimage.io.imread(imgFile)
    if len(im.shape) == 2:
        img = skimage.color.gray2rgb(im)
    paras['im'] = img
    paras['img'] = img
    save_hierachecalRegionsProcess(paras)
    if paras['is_rotate']:
        regions, angle = special_common_local_proposal(paras)
    else:
        regions = special_common_local_proposal(paras)
    # regions = list(regions)
    print np.array(regions)
    if paras['train']:
        for k, v in regions.iteritems():
            plf.showGrid(img, v)
            plt.title(k)
        plt.show()
    else:
        if paras['is_rotate']:
            img = rotate(img, angle)
        plf.showGrid(img, regions)
        plt.savefig(figSaveFolder + name + '.png')
        plt.show()

    # im = skimage.io.imread(imgFile)
    # if len(im.shape) == 2:
    #     img = skimage.color.gray2rgb(im)

    # (R, F, L, L_regions) = selective_search.hierarchical_segmentation(img, k, feature_masks, eraseMap=None)
    # print('result filename: %s_[0000-%04d].png' % (out_prefix, len(F) - 1))
Esempio n. 5
0
 # # print feaVecs.shape, posVecs.shape
 # labelVecs = chm.calPatchLabels2(w, feaVecs, k=nk, two_classes=['1', '2'], isH1=True)
 # posVecs_f, labelVecs_f = filterPos(posVecs, labelVecs, radius=3, spaceSize=10)
 # specialIDs = list(np.argwhere(labelVecs_f == 0)[:, 0])
 # specialPos = list(posVecs_f[specialIDs, :])
 wordsFile_s = [
     lbp_wordsFile_s1, lbp_wordsFile_s2, lbp_wordsFile_s3, lbp_wordsFile_s4
 ]
 specialType = 2
 w = wordsFile_s[specialType]
 patchData_a, specialPos = selectSpecialPatch(imgFile, w, feaType, gridSize,
                                              sizeRange, nk)
 # print labelVecs.shape
 print len(specialPos)
 print len(patchData_a)
 im = imread(imgFile)
 patchData, _, _ = esg.generateGridPatchData(im,
                                             gridSize,
                                             sizeRange,
                                             gridList=specialPos)
 print len(patchData)
 pp = np.array(patchData)
 background_mean = pp.mean()
 print background_mean
 mm = np.mean(np.mean(pp, axis=2), axis=1)
 print mm.shape
 plf.showGrid(im, specialPos)
 plt.show()
 specialList = threshHoldFilterPatch(im, gridSize, sizeRange)
 plf.showGrid(im, specialList)
 plt.show()
Esempio n. 6
0
    plt.plot(radius, sizes)
    plt.show()

    labelFile = '../../Data/balanceSampleFrom_one_in_minute.txt'
    imagesFolder = '../../Data/labeled2003_38044/'
    imgType = '.bmp'
    gridSize = np.array([10, 10])
    sizeRange = (16, 16)

    [images, labels] = plf.parseNL(labelFile)

    # imgFile = imagesFolder + images[0] + imgType
    imName = 'N20031221G094901'
    saveFolder = '/home/ljm/NiuChuang/KLSA-auroral-images/Data/Results/sample_grid/'
    imgFile = imagesFolder + imName + imgType

    # im = Image.open(imgFile)
    # im = np.array(im)

    # imageSize = np.array(im.shape)
    # gridList = generateGrid(imageSize, gridSize, sizeRange)
    gridPatchData, gridList, im = generateGridPatchData(
        imgFile, gridSize, sizeRange)

    # print gridList[0:5]
    # print len(gridList)
    plf.showGrid(im, gridList)
    plt.savefig(saveFolder + imName + '_grid.jpg')
    # plt.imsave('/home/ljm/NiuChuang/KLSA-auroral-images/Data/Results/sample_grid/N20040118G050641_grid.jpg')
    plt.show()