img = np.array(range(100)).reshape([10,10])
img = np.zeros([100,100])
img[0:50,0:50] = 1
win_size = 2
def SlidingWindow(win_size,img):
split_img = []
yx = []
for i in range(img.shape[0]-win_size+1):
for j in range(img.shape[1]-win_size+1):
split_img.append(img[i:i+win_size,j:j+win_size])
yx.append([i,j])
all = []
for img_,yx_ in zip(split_img,yx):
all = all + [(i+yx_[0],j+yx_[1]) for (i,j) in list(zip(*np.where(img_ == 1)))]
return Counter(all)
SlidingWindow(4,img)
Recommended Posts