forked from justinbois/bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_processing_round_two.py
76 lines (54 loc) · 1.74 KB
/
image_processing_round_two.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import numpy as np
# Our image processing tools
import skimage.filters
import skimage.io
import skimage.measure
import skimage.morphology
import skimage.segmentation
import matplotlib.pyplot as plt
import seaborn as sns
rc={'lines.linewidth': 2, 'axes.labelsize': 18, 'axes.titlesize': 18}
sns.set(rc=rc)
sns.set_style('dark')
# Load an example phase image.
phase_im = skimage.io.imread('data/HG105_images/noLac_phase_0004.tif')
# Show the image.
plt.imshow(phase_im, cmap=plt.cm.viridis)
plt.show()
plt.close()
# Apply a gaussian blur to the image.
im_blur = skimage.filters.gaussian(phase_im, 50)
# Convert our phase image to a float.
phase_float = skimage.img_as_float(phase_im)
phase_sub = phase_float - im_blur
# Show both
plt.figure()
plt.imshow(phase_float, cmap=plt.cm.viridis)
plt.title('original')
plt.figure()
plt.imshow(phase_sub, cmap=plt.cm.viridis)
plt.title('subtracted')
# Apply otsu thresholding
thresh = skimage.filters.threshold_otsu(phase_sub)
seg = phase_sub < thresh
# Plot segmentation
plt.close('all')
plt.imshow(seg, cmap=plt.cm.Greys_r)
# Label 'em
seg_lab, num_cells = skimage.measure.label(seg, return_num=True, background=0)
plt.close()
plt.imshow(seg_lab, cmap=plt.cm.Spectral_r)
# Compute the region properties and extract area of each object
ip_dist = 0.063 # micron per pixel
props = skimage.measure.regionprops(seg_lab)
# Get the areas as an array
areas = np.array([prop.area for prop in props])
cutoff = 300
im_cells = np.copy(seg_lab) > 0
for i,_ in enumerate(areas):
if areas[i] < cutoff:
im_cells[seg_lab==props[i].label] = 0
area_filt_lab = skimage.measure.label(im_cells)
plt.figure()
plt.imshow(area_filt_lab, cmap=plt.cm.Spectral_r)
im_fl = skimage.io.imread('data/HG105_images/noLac_FITC_0004.tif')