-
Notifications
You must be signed in to change notification settings - Fork 0
/
cut_out_mitosis.py
57 lines (44 loc) · 1.09 KB
/
cut_out_mitosis.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 sys
sys.path.append("/home/appl/opencv-2.4.6.1/lib/python2.6/site-packages")
import numpy as np
import cv2
from common import anorm, getsize
import os
def read_csv(filename):
f = open(filename)
lines = f.readlines()
f.close()
res = []
for line in lines:
tm = line.split(",")
tmp = []
tmp.append(tm[0].strip("\t"))
tmp.append(tm[1].strip("\t"))
res.append(tmp)
return res
def cutout(img ,csv, file_name, size):
print img
src = cv2.imread(img, 1)
i = 0
half = size/2
for point in csv:
dst = src[int(point[1])-half:int(point[1])+half, int(point[0])-half:int(point[0])+half]
i += 1
tmp_name = file_name.split("/")
tmp = tmp_name[-1] + str(i) +".jpg"
try:
if len(dst[0]) == size and len(dst) == size:
cv2.imwrite(tmp, dst)
except:
print "Not found"
def set_path(img):
name = img.split("/")
return name[-1][0:8] + ".tiff"
if __name__ == "__main__":
argvs = sys.argv
filename = argvs[1]
img = argvs[2] + set_path(argvs[1])
print img
print "------"
csv = read_csv(filename)
cutout(img, csv, filename, 50)