-
Notifications
You must be signed in to change notification settings - Fork 0
/
LabelCleaning.py
57 lines (47 loc) · 1.66 KB
/
LabelCleaning.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
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np
import os
from functools import reduce
import tifffile as tiff
class Annotate(object):
def __init__(self):
self.ax = plt.gca()
self.rect = Rectangle((0, 0), 1, 1, facecolor='None')
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.ax.add_patch(self.rect)
self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
def on_press(self, event):
# print 'press'
self.x0 = event.xdata
self.y0 = event.ydata
def on_release(self, event):
# print 'release'
self.x1 = event.xdata
self.y1 = event.ydata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.ax.figure.canvas.draw()
return [self.x0, self.x1, self.y0, self.y1]
#CHOOSE
# MF = 'Z:/rappez/20170622_Hepa_June_DAN_Untreated_FA_LPS_TNFa\Data/transformation_2/LPS_1.2_SELECTED/'
MFA = MF + 'Analysis/'
Path = MFA + 'CellProfilerAnalysis/Labelled_cells'
img = tiff.imread(Path + '.tiff')
plt.imshow(img, interpolation = 'none')
print(np.shape(np.unique(img)))
lbl_correct = img
a = Annotate()
indexes = np.unique(img[int(a.y0):int(a.y1), int(a.x0):int(a.x1)])
for ind in indexes:
lbl_correct[img == ind] = 0.0
plt.imshow(lbl_correct, interpolation = 'none')
a = Annotate()
# lbl_correct = lbl_correct.astype('uint16')
os.rename(Path + '.tiff', Path + '_OLD.tiff')
tiff.imsave(Path + '.tiff', lbl_correct)