提到python中的这个很棒的滑动窗口实现:https://github.com/keepitsimple/ocrtest/blob/master/sliding_window.py#blob_contributors_box,我的问题是——在代码中的哪一个地方可以看到图像上当前窗口的位置? 或者我怎样才能知道它的位置?在
在第72行和第85行之后,我尝试打印出shape
和{norm_shape
函数中,我打印出了tuple
,但输出的只是窗口尺寸(如果我也理解正确的话)。在
但我不仅需要尺寸,比如宽度和高度,还需要知道从图像中提取窗口的位置,像素坐标,或者图像中的行/列。在
如果您尝试使用
flatten=False
要在图像上创建窗口的“网格”:要获得相应的像素坐标,可以执行以下操作:
^{pr2}$使用
flatten=True
,64x64像素窗口的8x8网格将被展平成64个64x64像素窗口的长矢量。那样的话你 可以使用np.unravel_index
之类的方法从一维向量索引进行转换 在一个网格索引的元组中,然后使用这些来获得像素坐标 上图:好吧,我会尽力回答你在评论中提出的一些问题。在
也许我还不够清楚-你已经可以使用类似于我的
get_win_pixel_coords()
函数来完成这项工作,它提供窗口相对于图像的上、下、左和右坐标。例如:还请注意,我已经更新了}(即窗口不能完全平铺没有重叠的图像)。在
get_win_pixel_coords()
,以处理shiftSize
不是{不,如果窗口不重叠地平铺图像(即
shiftSize=None
,我目前为止一直假设),那么如果你让网格尺寸等于图像的像素尺寸,那么每个窗口只包含一个像素!在正如我所说,使“网格大小”等于图像尺寸是没有意义的,因为每个窗口只包含一个像素(至少,假设窗口是不重叠的)。12表示将索引放入扁平的窗口网格中,例如:
如前所述,您已经可以使用
get_win_pixel_coords()
返回的上、下、左、右坐标来获得窗口相对于图像的位置。如果您真的需要,可以将其打包成一个函数:如果需要窗口中每个像素相对于图像的坐标,另一个技巧是构造包含图像中每个像素的行和列索引的数组,然后将滑动窗口应用于这些:
因为scipy.misc.lena()在>;0.17中不再可用,所以要更新@ali\u m answer's。下面是一个使用RGB图像scipy.misc.face()的示例,对OP中提供的滑动窗口源代码稍作修改
将返回变量
newshape
添加到sliding_window()
可以传递flatten=True
,并且仍然知道滑动窗口函数创建的网格的性质。在我的应用程序中,计算窗口的展平向量是可取的,因为这是一个很好的点来缩放应用于每个计算窗口的计算。在如果一个96x96窗口(即
^{pr2}$tile
xtile
)在两个方向上有50%的重叠应用于形状为(768,1024,3)
的图像,则可以对输入图像进行填充,以确保在创建滑动窗口之前,输入图像可以被N个没有余数的窗口整除。在计算窗口的网格包含15行21列和315个计算窗口。}的索引来确定。如果我们对第239个计算窗口感兴趣:
grid_pos
可以使用计算窗口的平坦向量(即win
)、ind[0]
和{然后,可以使用以下方法找到原始图像中计算窗口的边界坐标:
相关问题 更多 >
编程相关推荐