extract_imgBand_patches

(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()

参数详解:https://stackoverflow.com/questions/40731433/understanding-tf-extract-image-patches-for-extracting-patches-from-an-image?newreg=2f7aa12c4b6d4870a979698318d457a4

命令功能:针对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]])

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值