In [1]:
%run ../common.ipynb
img = imread('../mp.tif')
img = smooth(img, 5)
In [2]:
sobel0 = numpy.zeros(img.shape, dtype=np.int)
ndimage.sobel(img, axis=0, output=sobel0)
sobel1 = numpy.zeros(img.shape, dtype=np.int)
ndimage.sobel(img, axis=1, output=sobel1)
imshow(sobel0)
imshow(sobel1)
Out[2]:
In [3]:
type(sobel1[0,0])
Out[3]:
In [24]:
histshow(img)
figure()
h = np.histogram(sobel0.flatten(), bins=360)
plt.hist(h[0], bins=h[1])
plt.show()
In [ ]:
sobel = numpy.sqrt(sobel0**2 + sobel1**2)
sobel[sobel<10]=0
imshow(sobel)
In [ ]:
mask = numpy.zeros((7,7))
mask[:,3] = 1
er = ndimage.binary_erosion(sobel, structure=mask)
mask_dil = numpy.zeros((9,9))
mask_dil[:,3:6] = 1
dil = ndimage.binary_dilation(er, structure=mask_dil)
imshow(dil)
In [ ]:
mask = numpy.zeros((7,7))
mask[3,:] = 1
er = ndimage.binary_erosion(sobel, structure=mask)
mask_dil = numpy.zeros((9,9))
mask_dil[3:6,:] = 1
dil = ndimage.binary_dilation(er, structure=mask_dil)
imshow(dil)
In [ ]:
degree = numpy.arctan2(sobel0, sobel1)
imshow(degree)
In [ ]:
imsave("degree.tif", degree)
In [ ]:
degree.max()
In [ ]:
degree.min()
In [ ]:
imsave("degree.tif", scale(degree))
In [ ]:
histshow(scale(degree))