import skimage
skimage.__version__
'0.9.1'
from matplotlib import pyplot as plt
import numpy as np
bright_raw = plt.imread('Pos60051.png')
plt.imshow(bright_raw)
<matplotlib.image.AxesImage at 0xa4e826c>
bright_raw.dtype
dtype('float32')
bright_raw.shape
(1536, 2048, 3)
from skimage.filter import gaussian_filter
bright_blurred = gaussian_filter(bright_raw, sigma=30)
/usr/local/lib/python2.7/dist-packages/scikit_image-0.9.1-py2.7-linux-i686.egg/skimage/filter/_gaussian.py:96: RuntimeWarning: Images with dimensions (M, N, 3) are interpreted as 2D+RGB by default. Use `multichannel=False` to interpret as 3D image with last dimension of length 3. warnings.warn(RuntimeWarning(msg))
plt.imshow(bright_blurred)
<matplotlib.image.AxesImage at 0xa82c38c>
np.max(bright_blurred)
0.18542657233256457
np.max(bright_raw)
0.99610895
# skimage.filter.
from skimage.morphology import label
# Threshold
bright_regions = bright_blurred > 0.12
bright_regions.dtype
dtype('bool')
np.unique(bright_regions[:, :, 2])
# Only G channel contains data
array([False], dtype=bool)
label_regions = label(bright_regions[:, :, 1], neighbors=4, background=0)
label_regions.dtype
dtype('int32')
# Number of labels
np.unique(label_regions)
# or, simply,
np.max(label_regions)
# + 1
4
# plt.imshow(label_regions)
plt.colorbar(plt.imshow(label_regions))
<matplotlib.colorbar.Colorbar instance at 0xa996a0c>
from skimage import measure
intensity_regions = measure.regionprops(label_regions, ['MeanIntensity'], intensity_image=bright_raw[:, :, 1])
len(intensity_regions)
4
coord_regions = measure.regionprops(label_regions, ['coords'], intensity_image=bright_raw[:, :, 1])
coord_regions[0]['coords']
array([[291, 374], [291, 375], [291, 376], ..., [357, 431], [357, 432], [357, 433]])
np.where(label_regions==0)
(array([ 0, 0, 0, ..., 25, 25, 25]), array([384, 385, 386, ..., 416, 417, 418]))
for i in xrange(len(intensity_regions)):
print(intensity_regions[i]['MeanIntensity'])
0.205465755261 0.155044210443 0.275592330443 0.187728478964
from skimage.feature import match_template
np.where(label_regions==4)
(array([721, 721, 721, ..., 783, 783, 783]), array([819, 820, 821, ..., 803, 804, 805]))
region_4 = bright_raw[720:780, 780:840]
plt.imshow(region_4)
<matplotlib.image.AxesImage at 0xadc09ac>
region_matching = match_template(bright_raw[:, :, 1], region_4[:, :, 1])
plt.imshow(region_matching)
<matplotlib.image.AxesImage at 0xae3f0ac>
plt.gray()
plt.imshow(region_matching)
<matplotlib.image.AxesImage at 0xafc6f4c>
plt.imshow(plt.imread('longtime_z006.png'))
plt.axis('off')
(-0.5, 2399.5, 1174.5, -0.5)