In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [5]:
%run ../common.ipynb


Populating the interactive namespace from numpy and matplotlib
Matlab usage:

    %%matlab
    a = 1

or
    results = mlab.run_code('a=1;')

or

    res = mlab.run_func('path/to/function.m', {'arg1': 3, 'arg2': 5})

See https://github.com/arokem/python-matlab-bridge#usage for more details.

WARNING: pylab import has clobbered these variables: ['mlab', 'imshow', 'imread', 'imsave']
`%matplotlib` prevents importing * from pylab and numpy

In [6]:
images = imread('sample.tif')

In [7]:
images.shape


Out[7]:
(3, 3846, 3875)

In [8]:
for img in images:
    imshow(img)



In [9]:
img1 = images[1];

In [10]:
img1[100:110,100:110]


Out[10]:
array([[ 6,  6,  0,  6,  0, 20,  6,  0,  6,  6],
       [ 0,  6, 13,  0,  6, 13,  0,  6,  6,  0],
       [ 0,  6,  6,  0,  6,  0,  0,  0,  6,  0],
       [ 6,  6, 13,  0,  0,  0, 13,  6, 13,  0],
       [ 6,  6, 13,  6,  6,  0,  0,  0,  0, 13],
       [ 0, 13,  6,  0,  0,  0,  6, 26,  6,  0],
       [ 0,  6,  6, 20,  6,  0,  0,  6, 20, 13],
       [ 6,  6,  0, 20,  6, 13,  0, 13,  0,  0],
       [ 0,  0,  0, 13,  0,  6, 13,  6,  0,  6],
       [ 6,  0, 13,  6,  0,  0,  6,  0,  6,  6]], dtype=uint8)

In [11]:
imshow(img1, cmap='gray')


Out[11]:
(<matplotlib.figure.Figure at 0x10ef35990>,
 <matplotlib.axes._subplots.AxesSubplot at 0x124eac490>,
 <matplotlib.image.AxesImage at 0x124eae2d0>)

In [12]:
img1.max()


Out[12]:
255

In [13]:
img1.var()


Out[13]:
1335.7627316724995

In [14]:
img1.mean()


Out[14]:
35.804770771476022

In [15]:
img1[img1 < 10] = 0

In [16]:
imshow(img)


Out[16]:
(<matplotlib.figure.Figure at 0x116af7d90>,
 <matplotlib.axes._subplots.AxesSubplot at 0x116ae5550>,
 <matplotlib.image.AxesImage at 0x116b18590>)

In [19]:
def f(n):
    temp = np.copy(img1)
    temp[temp < n] = 0
    imshow(temp)

In [20]:
interact(f, n=(0,255,1))



In [21]:
histshow(img1)



In [ ]: