我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用skimage.transform.pyramid_gaussian()。
def save_pyramid () : global temp_line global pyramids global patchNum global total_patch global total_pyramid org_img = Image.open("%s/../fddb/%s.jpg" %(base_path, temp_line), 'r' ) org_img_name = "%s " %(temp_line) # original image name pyramids = list( pyramid_gaussian(org_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 i in range( len (pyramids) ) : row = pyramids[i].shape[0] col = pyramids[i].shape[1] im_matrix = np.zeros([row, col, 3]).astype('uint8') for k in range(row): for j in range(col): im_matrix[k,j] = pyramids[i][k,j] * 255 new_img = Image.fromarray(im_matrix) new_img.save("%s/pyramid-%s.jpg" %(ns_path, i+total_pyramid) ) # new_img.show() patchNum[i] = (row-MinFace+1) * (col-MinFace+1) # the number of patches total_pyramid = total_pyramid + len(pyramids) total_patch = total_patch + sum(patchNum) # -----------------------------------------
def __pyramid_ski__(frame,steps = 7,scale = 2): # create image pyramid from img, skimage implemetation py = pyramid_gaussian(frame, downscale = scale) return [sp.round_(255.0*e).astype(sp.uint8) for e in py][:steps]
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 # -----------------------------------------