PrepareNS_coco.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:mlstudy_week7 作者: ByungKeon-Ko 项目源码 文件源码
def create_ns (tmp_imgpath, cnt_ns ) :
    global pyramids

    tmp_img = Image.open("%s/%s" %(coco_path, tmp_imgpath), 'r' )
    pyramids = list( pyramid_gaussian( tmp_img, downscale=math.sqrt(2) ) )

    for i in range ( len(pyramids) ):
        if min( pyramids[i].shape[0], pyramids[i].shape[1] ) < MinFace :
            del pyramids[i:]
            break

    # for j in range(4) :
    for j in range(36) :
        # creating random index
        img_index = random.randint(0, len(pyramids)-1 )
        tmp_patch_num = ( pyramids[img_index].shape[0] - 12 + 1) * ( pyramids[img_index].shape[1] - 12 + 1)
        rand_index = random.randint(0, tmp_patch_num)

        # x, y position decoding
        row_max = pyramids[img_index].shape[0]
        col_max = pyramids[img_index].shape[1]
        row = 0
        col = rand_index

        while ( col >= col_max - 12 +1 ) :
            row = row + 1
            col = col - (col_max-12+1)

        flag = 0
        # Rejecting Black and White image
        tmp_ns = pyramids[img_index][row:row+12, col:col+12]
        if not len(tmp_ns.shape)==3 :
            print " Gray Image. Skip "
            return 0

        # Rejecting Positive Samples
        scale_factor = math.sqrt(2)**img_index

        tmp_ns = pyramids[img_index][row:row+12, col:col+12]
        tmp_ns = Image.fromarray((tmp_ns*255.0).astype(np.uint8) )
        # tmp_ns = tmp_ns.resize( (12,12), Image.BICUBIC )
        tmp_ns = tmp_ns.resize( (12,12), Image.BILINEAR )
        tmp_ns.save("%s/ns-%s.jpg" %(ns_path, cnt_ns+j) )

    return 1

# -----------------------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号