-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipeline_Combined_MatchingAndWateshed_looping.py
477 lines (341 loc) · 19.4 KB
/
Pipeline_Combined_MatchingAndWateshed_looping.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 22 21:22:46 2021
@author: genevieve.hayes
Template Matching Pipeline with Gata3- Identification
"""
# In[0]: IMPORT
# import the necessary packages
from __future__ import print_function
from PIL import Image
from skimage.feature import peak_local_max
from skimage.morphology import watershed
from scipy import ndimage
import argparse
import imutils
import cv2
import numpy as np
import random as rng
import MTM
import pandas as pd
from MTM import matchTemplates, drawBoxesOnRGB
import matplotlib.pyplot as plt
import matplotlib
# In[00]: FUNCTIONS
def load_BGR_img(filepath):
#Loads BGR image at filepath (str type).
rng.seed(12345)
parser = argparse.ArgumentParser(description='Code for Image Segmentation with Distance Transform and Watershed Algorithm.\
Sample code showing how to segment overlapping objects using Laplacian filtering, \
in addition to Watershed and Distance Transformation')
parser.add_argument('--input', help='Path to input image.', default=filepath)
args = parser.parse_args()
BGR_img = cv2.imread(cv2.samples.findFile(args.input))
if BGR_img is None:
print('Could not open or find the image:', args.input)
exit(0)
return BGR_img
def create_red_mask(img):
#Convert image to HSV
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
hsv_color_min = np.array([160, 150, 100],np.uint8) #identifies red dye well
hsv_color_max = np.array([179, 255, 255],np.uint8)
#Define threshold color range to filter
mask_red = cv2.inRange(hsv_img, hsv_color_min, hsv_color_max)
#Get inverted mask (background)
mask_nored = cv2.bitwise_not(mask_red)
return mask_red, mask_nored
def create_light_red_mask(img):
#Convert image to HSV
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
#hsv_color_min = np.array([-1,70,20]) #identifies brown cells well in red region
#hsv_color_max = np.array([30,255,255])
hsv_color_min = np.array([100, 50, 100],np.uint8) #identifies red dye well
hsv_color_max = np.array([179, 255, 255],np.uint8)
#Define threshold color range to filter
mask_red = cv2.inRange(hsv_img, hsv_color_min, hsv_color_max)
#Get inverted mask (background)
mask_nored = cv2.bitwise_not(mask_red)
return mask_red, mask_nored
def removeRedRegionFromImage(img, mask_red):
#Convert image to HSV
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
#Bitwise-AND mask and original image
channel_red_hsv_img = cv2.bitwise_and(hsv_img, hsv_img, mask=mask_red)
ratio = cv2.countNonZero(mask_red)/(hsv_img.size/3)
percentage_redstain = np.round(ratio*100, 2)
#Get second masked value (background) mask must be inverted
mask_nored = cv2.bitwise_not(mask_red)
channel_nored_hsv_img = cv2.bitwise_and(hsv_img, hsv_img, mask=mask_nored)
channel_nored_img = cv2.cvtColor(channel_nored_hsv_img, cv2.COLOR_HSV2BGR)
#Set masked region to white
whiteimg = np.full(channel_nored_img.shape, 255, dtype=np.uint8) #make white image
img_redremoved = np.where(channel_nored_img[:,:] == [0,0,0], whiteimg, channel_nored_img) #here we replace black pixels.
return img_redremoved
def fill_mask_holes(mask, kernel):
''' Fill holes in the mask with a defined kernel.
Kernel can be rectangular (kernel = np.ones((10,10),np.uint8)),
cross (kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(20,25))),
or elliptical (kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(20,25))).
'''
closed_mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
return closed_mask
#WATERSHED PREPROCESSING FUNCTION
def preprocessing_for_watershed(image_nored):
# Invert input image
image = 255-image_nored
#Apply pyramid mean shift filtering
spatial_window_radius = 19
color_window_radius = 20
shifted = cv2.pyrMeanShiftFiltering(image, sp = spatial_window_radius, sr = color_window_radius)
# Convert the mean shift image to grayscale, then apply Otsu thresholding
gray = cv2.cvtColor(shifted, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
# Compute the exact Euclidean distance from every binary pixel to the nearest zero pixel, then find peaks in this distance map
minimum_distance_map_distance = 11 #3 #10
# Perform the distance transform algorithm
dist = cv2.distanceTransform(thresh, distanceType=cv2.DIST_L2, maskSize=3)
# Normalize the distance image for range = {0.0, 1.0} so we can visualize and threshold it
cv2.normalize(dist, dist, 0, 1.0, cv2.NORM_MINMAX)
localMax = peak_local_max(dist, indices=False, min_distance=minimum_distance_map_distance, labels=thresh)
# perform a connected component analysis on the local peaks, using 8-connectivity, then apply the Watershed algorithm
markers = ndimage.label(localMax, structure=np.ones((3, 3)))[0]
markersimg = np.array(markers*1000000, dtype="uint8")
return markers, thresh, dist, gray, markersimg
def BGRinBrownRange_whiteRegion(mean_colour_in_contourHSV):
hsv_color_min = np.array([-1,70,20]) #identifies brown cells well
hsv_color_max = np.array([30,255,255])
inHRange = (mean_colour_in_contourHSV[0]>hsv_color_min[0])*(mean_colour_in_contourHSV[0]<hsv_color_max[0])
inSRange = (mean_colour_in_contourHSV[1]>hsv_color_min[1])*(mean_colour_in_contourHSV[1]<hsv_color_max[1])
inVRange = (mean_colour_in_contourHSV[2]>hsv_color_min[2])*(mean_colour_in_contourHSV[2]<hsv_color_max[2])
inBrownRange = inHRange*inSRange*inVRange
return inBrownRange
def BGRinBlueRange_whiteRegion(mean_colour_in_contourHSV):
hsv_color_min = np.array([38, 0, 18],np.uint8) #identifies blue cells well
hsv_color_max = np.array([160, 255, 255],np.uint8)
inHRange = (mean_colour_in_contourHSV[0]>hsv_color_min[0])*(mean_colour_in_contourHSV[0]<hsv_color_max[0])
inSRange = (mean_colour_in_contourHSV[1]>hsv_color_min[1])*(mean_colour_in_contourHSV[1]<hsv_color_max[1])
inVRange = (mean_colour_in_contourHSV[2]>hsv_color_min[2])*(mean_colour_in_contourHSV[2]<hsv_color_max[2])
inBlueRange = inHRange*inSRange*inVRange
return inBlueRange
def BGRinBrownRange_redRegion(mean_colour_in_contourHSV):
hsv_color_min = np.array([-1,70,20]) #identifies brown cells well in red region
hsv_color_max = np.array([30,255,255])
inHRange = (mean_colour_in_contourHSV[0]>hsv_color_min[0])*(mean_colour_in_contourHSV[0]<hsv_color_max[0])
inSRange = (mean_colour_in_contourHSV[1]>hsv_color_min[1])*(mean_colour_in_contourHSV[1]<hsv_color_max[1])
inVRange = (mean_colour_in_contourHSV[2]>hsv_color_min[2])*(mean_colour_in_contourHSV[2]<hsv_color_max[2])
inBrownRange = inHRange*inSRange*inVRange
return inBrownRange
def BGRinBlueRange_redRegion(mean_colour_in_contourHSV):
hsv_color_min = np.array([38, 0, 18],np.uint8) #identifies blue cells well
hsv_color_max = np.array([160, 255, 255],np.uint8)
inHRange = (mean_colour_in_contourHSV[0]>hsv_color_min[0])*(mean_colour_in_contourHSV[0]<hsv_color_max[0])
inSRange = (mean_colour_in_contourHSV[1]>hsv_color_min[1])*(mean_colour_in_contourHSV[1]<hsv_color_max[1])
inVRange = (mean_colour_in_contourHSV[2]>hsv_color_min[2])*(mean_colour_in_contourHSV[2]<hsv_color_max[2])
inBlueRange = inHRange*inSRange*inVRange
return inBlueRange
def watershedSegmentation_redRegion(img, markers, thresh, dist, gray, markersimg, min_radius, max_radius):
colour_threshold = 160#120 #COLOUR THRESHOLD
HSV_cropimg = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
image = 255-image_nored # Invert input image
#Identify each rsegmented region
labels = watershed(-dist, markers, mask=thresh)
print("{} unique segments found".format(len(np.unique(labels)) - 1))
# loop over the unique labels returned by the Watershed algorithm
maskim = np.zeros(np.shape(image), dtype="uint8")
val = 0
radius = 6
r = np.zeros(len(np.unique(labels))+1, dtype="uint8")
mean_coloursBRG = np.zeros((len(np.unique(labels))+1,4), dtype="uint8")
total = 0;
brown = 0;
blue = 0;
for label in np.unique(labels):
#if the label is zero, we are examining the 'background' so simply ignore it
val = val+1
if label == 0:
continue
# otherwise, allocate memory for the label region and draw
# it on the mask
mask = np.zeros(gray.shape, dtype="uint8")
mask[labels == label] = 255
color1 = (list(np.random.choice(range(256), size=3)))
color =[int(color1[0]), int(color1[1]), int(color1[2])]
maskim[labels == label] = color
# detect contours in the mask and grab the largest one
cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
c = max(cnts, key=cv2.contourArea)
#draw a circle enclosing the object
((x, y), r[val]) = cv2.minEnclosingCircle(c)
#Get mean colour inside each contour
mean_colour_in_contourBRG = cv2.mean(img,mask)
mean_colour_in_contourHSV = cv2.mean(HSV_cropimg,mask)
mean_coloursBRG[val, :] = mean_colour_in_contourBRG
intensity = np.around(mean_colour_in_contourBRG[0],0)
inBrownRange = BGRinBrownRange_redRegion(mean_colour_in_contourHSV)
inBlueRange = BGRinBlueRange_redRegion(mean_colour_in_contourHSV)
if r[val] > min_radius and r[val] < max_radius:
total = total+1;
#Draw Contours
#Green
if inBrownRange > 0.5:
cv2.drawContours(img, cnts, -1, (0,255,0), 1)
#cv2.putText(cropped_image, "#{}".format(mean_colour_in_contourBRG), (int(x) - 10, int(y)),
#ONT_HERSHEY_SIMPLEX, 0.3, (255, 255, 255), 2)
brown = brown+1;
#Blue
elif inBlueRange > 0.5:
cv2.drawContours(img, cnts, -1, (255,0,0), 1)
##cv2.putText(cropped_image, "#{}".format(mean_colour_in_contourBRG), (int(x) - 10, int(y)),
##ONT_HERSHEY_SIMPLEX, 0.3, (255, 255, 255), 2)
blue = blue+1;
markersimg = cv2.circle(markersimg,(int(x), int(y)), int(radius), 255, -1)
return img, total, brown, blue
# In[1]: LOAD AND CROP IMAGE AND FEATURES
SAVEIMG = 0
# high res parameters
min_radius_kn = 3
max_radius_kn = 18
min_radius_kp = 3
max_radius_kp = 18
#filepath = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Sample 6B/Bladder 1 TMA - QATA3_sample6B.tiff"
filepath = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Bladder 1 TMA - Sample 6D.tiff"
#filepath = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Bladder 1 TMA - Sample 6G.tiff"
#filepath = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Sample6B.tiff"
#filepath = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Sample6G.tiff"
#filepath = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Sample6D.tiff"
filepath_featurekngp = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5neg_gata3pos.tiff"
filepath_featurekngp_2 = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5neg_gata3pos_2.tiff"
filepath_featurekngp_3 = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5neg_gata3pos_7.tiff"
filepath_featurekngp_4 = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5neg_gata3pos_4.tiff"
filepath_featurekngp_5 = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5neg_gata3pos_5.tiff"
filepath_featurekpgp = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5pos_gata3pos.tiff"
filepath_featurekpgp_2 = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5pos_gata3pos_2.tiff"
filepath_featurekpgp_3 = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5pos_gata3pos_3.tiff"
filepath_featurekpgp_4 = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5pos_gata3pos_4.tiff"
filepath_featurekpgp_5 = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5pos_gata3pos_5.tiff"
filepath_featurekngn = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5neg_gata3neg.tiff"
filepath_featurekngn_2 = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5neg_gata3neg_2.tiff"
filepath_featurekngn_3 = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5neg_gata3neg_3.tiff"
filepath_featurekpgn = "/Users/genevieve.hayes/Desktop/ENPH 455 Thesis/Features/krt5pos_gata3neg.tiff"
BGR_fullimg = load_BGR_img(filepath)
BGR_featureimg_kngp = load_BGR_img(filepath_featurekngp)
BGR_featureimg_kngp_2 = load_BGR_img(filepath_featurekngp_2)
BGR_featureimg_kngp_3 = load_BGR_img(filepath_featurekngp_3)
BGR_featureimg_kngp_4 = load_BGR_img(filepath_featurekngp_4)
BGR_featureimg_kngp_5 = load_BGR_img(filepath_featurekngp_5)
BGR_featureimg_kpgp = load_BGR_img(filepath_featurekpgp)
BGR_featureimg_kpgp_2 = load_BGR_img(filepath_featurekpgp_2)
BGR_featureimg_kpgp_3 = load_BGR_img(filepath_featurekpgp_3)
BGR_featureimg_kpgp_4 = load_BGR_img(filepath_featurekpgp_4)
BGR_featureimg_kpgp_5 = load_BGR_img(filepath_featurekpgp_5)
BGR_featureimg_kngn = load_BGR_img(filepath_featurekngn)
BGR_featureimg_kngn_2 = load_BGR_img(filepath_featurekngn_2)
BGR_featureimg_kngn_3 = load_BGR_img(filepath_featurekngn_3)
BGR_featureimg_kpgn = load_BGR_img(filepath_featurekpgn)
cv2.imshow('Full image', BGR_fullimg)
cv2.waitKey(1)
Nx, Ny, w = np.shape(BGR_fullimg)
x_iterations = np.floor(Nx/500)
y_iterations = np.floor(Ny/500)
TOTAL_kngn = np.array([])
TOTAL_kngp = np.array([])
TOTAL_kpgn = np.array([])
TOTAL_kpgp = np.array([])
#In[2]: CROP IMAGE
for ind_x in range(0, int(x_iterations)):
for ind_y in range(0, int(y_iterations)):
BGR_cropimg = BGR_fullimg[ind_x*500:(ind_x*500+500),ind_y*500:(ind_y*500+500)]
BGR_cropimg_duplicate = BGR_cropimg
cv2.imshow('Original Image', BGR_cropimg)
cv2.waitKey(1)
print("------------------------------------------------- ")
print("\nImage Coordinates: ",ind_x*500,ind_y*500)
#In[3]: IDENTIFY RED REGION AND FILL IN HOLES
mask_red, mask_nored = create_red_mask(BGR_cropimg)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(20,25))
mask_closedred = fill_mask_holes(mask_red, kernel)
#In[4]: REMOVE FILLED RED REGION FROM IMAGE
image_nored = removeRedRegionFromImage(BGR_cropimg, mask_closedred)
cv2.imshow('No red white region',image_nored)
cv2.waitKey(1)
#In[4]: APPLY TEMPLATE MATCHING WITHOUT RED REGION
listTemplate_inwhite = [('A', BGR_featureimg_kngp),('B', BGR_featureimg_kngp_2),('G', BGR_featureimg_kngp_3),('D', BGR_featureimg_kngp_4)]#,('E', BGR_featureimg_kngp_5)]
Hits = matchTemplates(listTemplate_inwhite, image_nored, score_threshold=0.55, method=cv2.TM_CCOEFF_NORMED, maxOverlap=0)
Overlay_inwhite = drawBoxesOnRGB(image_nored, Hits, showLabel=True)
total_inwhite = len(Hits)
listTemplate_blueinwhite = [('*A', BGR_featureimg_kngn),('*B', BGR_featureimg_kngn_2),('*C', BGR_featureimg_kngn_3)]
Hits_blueinwhite = matchTemplates(listTemplate_blueinwhite, image_nored, score_threshold=0.75, method=cv2.TM_CCOEFF_NORMED, maxOverlap=0)
Overlay_blueinwhite = drawBoxesOnRGB(image_nored, Hits_blueinwhite, showLabel=True)
total_blueinwhite = len(Hits_blueinwhite)
print('\n KRT5 -\n')
print('Number of GATA3+ segments identified:', total_inwhite)
print('Number of GATA3- segments identified:', total_blueinwhite)
cv2.imshow('KRT5- Region', Overlay_inwhite)
cv2.waitKey(1)
#In[6]: INVERT MASK TO GET ONLY RED REGION
mask_closed_nored = cv2.bitwise_not(mask_closedred)
image_justred = removeRedRegionFromImage(BGR_cropimg, mask_closed_nored)
cv2.imshow('Red region', image_justred)
cv2.waitKey(1)
#In[7]: REMOVE RED STAIN FROM RED REGION IMAGE
mask_red_noredstain, mask_red_redstain = create_light_red_mask(image_justred)
image_redregion_noredstain = removeRedRegionFromImage(image_justred, mask_red_noredstain)
cv2.imshow('No red red region', image_redregion_noredstain)
cv2.waitKey(1)
#In[8]: APPLY WATERSHED SEGMENTATION TO RED REGION WITHOUT STAIN + IDENTIFY THE BROWN RANGE AND BLUE RANGE CELLS (KRT5+) + REMOVE NOISE
markers_red, thresh_red, dist_red, gray_red, markersimg_red = preprocessing_for_watershed(image_redregion_noredstain)
BGR_cropimg_watershed_inred, total_inred, brown_inred, total_blueinred = watershedSegmentation_redRegion(BGR_cropimg_duplicate, markers_red, thresh_red, dist_red, gray_red, markersimg_red, min_radius_kp, max_radius_kp)
#plt.subplot(1, 2, 1)
#plt.imshow(BGR_cropimg_watershed_inred)
#plt.subplot(1, 2, 2)
#plt.imshow(Overlay_inwhite)
#plt.show()
combined_img = cv2.hconcat((BGR_cropimg_watershed_inred, Overlay_inwhite))
cv2.imshow("Combined Segmentation Images", combined_img)
cv2.waitKey(1)
# show the output watershed image
cv2.imshow("Total Watershed Segmented Image", BGR_cropimg_watershed_inred)
cv2.waitKey(1)
print('\n KRT5 +\n')
print('Number of GATA3+ segments identified:', total_inred)
print('Number of GATA3- segments identified:', total_blueinred)
#cv2.imshow('KRT5+ Region', Overlay_inred)
#cv2.waitKey(1)
#Total_overlay = drawBoxesOnRGB(BGR_cropimg, pd.concat([Hits,Hits_inred]), showLabel=True)
#cv2.imshow('KRT5+ Region', Total_overlay)
#cv2.waitKey(1)
TOTAL_kngn = np.append(TOTAL_kngn, total_blueinwhite)
TOTAL_kngp = np.append(TOTAL_kngp, total_inwhite)
TOTAL_kpgp = np.append(TOTAL_kpgp, total_inred)
TOTAL_kpgn = np.append(TOTAL_kpgn, total_blueinred)
if SAVEIMG == 1:
filename_output = "Outputs_CHR6D/"+str(ind_x)+str(ind_y)+ "processed_img_section.tiff"
cv2.imwrite(filename_output, combined_img)
print('- Image Saved -')
print('\nIMAGE PROCESSING COMPLETE')
print('---- ---- ---- ----')
print('\nTOTAL KRT5-/GATA3+:', np.sum(TOTAL_kngp))
print('TOTAL KRT5+/GATA3+:', np.sum(TOTAL_kpgp))
print('TOTAL KRT5+/GATA3-:', np.sum(TOTAL_kpgn))
print('TOTAL KRT5-/GATA3-:', np.sum(TOTAL_kngn))
# In[]: BAR PLOTS
x = np.array(["Sample6B"])
y = np.array([np.sum(TOTAL_kngp),np.sum(TOTAL_kngn),np.sum(TOTAL_kpgp),np.sum(TOTAL_kpgn)])
width = 0.2
matplotlib.rc('font', serif='Helvetica Neue')
matplotlib.rc('text', usetex='false')
matplotlib.rcParams.update({'font.size': 16})
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(4.5, 5.5)
#plt.bar(x,y)
p1 = plt.bar(x, y[0], width, color='g')
p2 = plt.bar(x, y[1], width, bottom=y[0], color='c')
p3 = plt.bar(x, y[2], width, bottom=y[0]+y[1], color='r')
p4 = plt.bar(x, y[3], width, bottom=y[0]+y[1]+y[2], color='b')
plt.ylabel("Number of Cells Identified")
plt.legend((p1[0], p2[0], p3[0], p4[0]), ('KRT5-/GATA3+', 'KRT5-/GATA3-', 'KRT5+/GATA3+', 'KRT5+/GATA3-'), fontsize=10, ncol=1, framealpha=0, fancybox=True,bbox_to_anchor=(1.04,1))
plt.show()