(1)问题介绍
目的:提取序列图像的patch
函数和模块:
import tensorflow as tf
import numpy as np
import pickle
tf.extract_image_patches()
np.expand_dims(imgData[:,:,d], axis=0)
数据:
band1 = [[[[x * n + y + 1] for y in range(n)] for x in range(n)]] #shape = (1, 10, 10, 1)
band2 = band1
images = np.concatenate((band1,band2),axis=3) #shape = (1, 10, 10, 2)
band1 Out[112]:
[[[[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]],
[[11], [12], [13], [14], [15], [16], [17], [18], [19], [20]],
[[21], [22], [23], [24], [25], [26], [27], [28], [29], [30]],
[[31], [32], [33], [34], [35], [36], [37], [38], [39], [40]],
[[41], [42], [43], [44], [45], [46], [47], [48], [49], [50]],
[[51], [52], [53], [54], [55], [56], [57], [58], [59], [60]],
[[61], [62], [63], [64], [65], [66], [67], [68], [69], [70]],
[[71], [72], [73], [74], [75], [76], [77], [78], [79], [80]],
[[81], [82], [83], [84], [85], [86], [87], [88], [89], [90]],
[[91], [92], [93], [94], [95], [96], [97], [98], [99], [100]]]]
(2)操作
命令:
with tf.Session() as sess:
patch = tf.extract_image_patches(images=images,
ksizes=[1, 3, 3, 1], strides=[1, 1, 1, 1],
rates=[1, 1, 1, 1], padding='VALID').eval()
命令功能:针对bands=2的影像,提取3*3的patch,进行排列。排列规则如下
#patch的shape是(1, 8, 8, 18)
#原图像,最左列的patch索引如下:
patch[0,:,0,:]
左上角像元对应的patch索引如下:
patch[0,0,0,:],具体排列见Out[119]:
array([ 1, 1, 2, 2, 3, 3, 11, 11, 12, 12, 13, 13, 21, 21, 22, 22, 23,
23])
回看patch[0,:,0,:],具体排列见Out[117]:
array([[ 1, 1, 2, 2, 3, 3, 11, 11, 12, 12, 13, 13, 21, 21, 22, 22,
23, 23],
[11, 11, 12, 12, 13, 13, 21, 21, 22, 22, 23, 23, 31, 31, 32, 32,
33, 33],
[21, 21, 22, 22, 23, 23, 31, 31, 32, 32, 33, 33, 41, 41, 42, 42,
43, 43],
[31, 31, 32, 32, 33, 33, 41, 41, 42, 42, 43, 43, 51, 51, 52, 52,
53, 53],
[41, 41, 42, 42, 43, 43, 51, 51, 52, 52, 53, 53, 61, 61, 62, 62,
63, 63],
[51, 51, 52, 52, 53, 53, 61, 61, 62, 62, 63, 63, 71, 71, 72, 72,
73, 73],
[61, 61, 62, 62, 63, 63, 71, 71, 72, 72, 73, 73, 81, 81, 82, 82,
83, 83],
[71, 71, 72, 72, 73, 73, 81, 81, 82, 82, 83, 83, 91, 91, 92, 92,
93, 93]])