在图像上找到5x5滑动窗口,并获取每个窗口的所有索引(索引)

时间:2017-04-07 23:42:50

标签: python arrays numpy

如何在图像上获取5x5窗口的值,是否有任何方法可以将每个窗口的所有25个索引作为int数字或字符串形式0,0 0,1 0,2保存在文本文件中在原始图像上?

1 个答案:

答案 0 :(得分:0)

Ok, here are a few hints to get you started. But this is basic stuff, please forgive my saying so but you should probably work through a tutorial or two.

To get a 5x5 window the straight forward way is slicing:

window = img[i:i+5, j:j+5]

here i, j are the coordinates of your window's top left corner and should lie between 0, 0 and N-5, M-5 where NxM[x3] is the size of your image. The x3 will be there if you have three colour channels.

To slide the window you can loop over i and j or use the trickery from the post I've linked to in the comments.

The indices you can get with indices:

np.moveaxis(np.indices((5, 5)), 0, -1) + (i, j)

but saving them all seems a bit wasteful, it would suffice to store i, j, 5, 5