In [1]:
%run ../../common.ipynb
import scipy.misc, tifffile
from IPython.html.widgets import interact, IntTextWidget, FloatTextWidget


Populating the interactive namespace from numpy and matplotlib

In [6]:
img = scipy.misc.lena().astype(float32)
#img = imread('../mp.tif')
#%pylab qt
imshow(img, figure=figure(figsize=(12,12)))


Out[6]:
<matplotlib.image.AxesImage at 0x1076ddc10>

In [7]:
G = ndimage.gaussian_filter(img, sigma=2.2)
LoG = np.zeros(img.shape, dtype=np.int)
ndimage.laplace(G, LoG)
gimshow(scale(LoG))



In [8]:
y,x = img.shape

# arrays for zero-crossing detection
vertical   = np.zeros(img.shape, dtype=np.int8)
horisontal = np.zeros(img.shape, dtype=np.int8)
plus45     = np.zeros(img.shape, dtype=np.int8)
minus45    = np.zeros(img.shape, dtype=np.int8)

vertical  [1:y-1,0:x  ] = LoG[0:y-2,0:x  ] * LoG[2:y,0:x  ]
horisontal[0:y  ,1:x-1] = LoG[0:y  ,0:x-2] * LoG[0:y,2:x  ]
plus45    [1:y-1,1:x-1] = LoG[0:y-2,2:x  ] * LoG[2:y,0:x-2]
minus45   [1:y-1,1:x-1] = LoG[0:y-2,0:x-2] * LoG[2:y,2:x  ]

In [9]:
threshold = -0
# make image with all orientations of edges
edges = np.zeros(img.shape, dtype=np.int8)
edges[horisontal < threshold] = 1
edges[vertical < threshold] = 1
edges[plus45   < threshold] = 1
edges[minus45  < threshold] = 1
gimshow(edges)



In [10]:
def fn(sigma=1, threshold=0):
    G = ndimage.gaussian_filter(img, sigma=sigma)
    LoG = np.zeros(img.shape, dtype=np.int)
    ndimage.laplace(G, LoG)
    y,x = img.shape

    # arrays for zero-crossing detection
    vertical   = np.zeros(img.shape, dtype=np.int8)
    horisontal = np.zeros(img.shape, dtype=np.int8)
    plus45     = np.zeros(img.shape, dtype=np.int8)
    minus45    = np.zeros(img.shape, dtype=np.int8)

    vertical  [1:y-1,0:x  ] = LoG[0:y-2,0:x  ] * LoG[2:y,0:x  ]
    horisontal[0:y  ,1:x-1] = LoG[0:y  ,0:x-2] * LoG[0:y,2:x  ]
    plus45    [1:y-1,1:x-1] = LoG[0:y-2,2:x  ] * LoG[2:y,0:x-2]
    minus45   [1:y-1,1:x-1] = LoG[0:y-2,0:x-2] * LoG[2:y,2:x  ]

    # make image with all orientations of edges
    edges = np.zeros(img.shape, dtype=np.int8)
    edges[horisontal < threshold] = 1
    edges[vertical < threshold] = 1
    edges[plus45   < threshold] = 1
    edges[minus45  < threshold] = 1
    plt.figure(figsize=(16,8))
    plt.subplot(121)
    plt.imshow(edges, cmap="gray")
    plt.subplot(122)
    plt.imshow(img)

In [11]:
interact(fn, sigma=FloatTextWidget(min=1, max=20, value=1.0), threshold=IntTextWidget(min=-20, max=0, value=0))



In [12]:
%pylab qt
img = tifffile.imread('../mp.tif')
interact(fn, sigma=FloatTextWidget(min=1, max=20, value=1.0), threshold=IntTextWidget(min=-20, max=0, value=0))