Skip to content

Instantly share code, notes, and snippets.

@Lyken17
Created March 13, 2017 01:02
Show Gist options
  • Save Lyken17/971cd19b78d5611efcdaa10596a6da9e to your computer and use it in GitHub Desktop.
Save Lyken17/971cd19b78d5611efcdaa10596a6da9e to your computer and use it in GitHub Desktop.
# coding: utf-8
# In[127]:
import numpy as np
from scipy.signal import convolve2d as conv2d
p_label = np.array([[[1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0]],
[[1, 0, 0], [1, 0, 0], [0, 1, 0], [0, 1, 0], [1, 0, 0], [1, 0, 0]],
[[1, 0, 0], [1, 0, 0], [0, 1, 0], [0, 1, 0], [1, 0, 0], [1, 0, 0]],
[[1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0]]])
# In[128]:
p_label.shape
# In[133]:
kernel = np.array([[1, 2, 1], [2, 4, 2], [1, 2, 1]]) / 16.0
# In[134]:
kernel, kernel.shape
# In[135]:
print(p_label[:,:,0])
print(conv2d(p_label[:,:,0], kernel, boundary='fill', mode='same'))
# In[136]:
print(p_label[:,:,1])
print(conv2d(p_label[:,:,1], kernel, boundary='fill', mode='same'))
# In[ ]:
# In[ ]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment