-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessors.py
46 lines (34 loc) · 1.27 KB
/
processors.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
"""Image processor methods"""
# from skimage import io
from skimage.color import rgb2hed
from skimage.exposure import rescale_intensity
# from PIL import Image
import matplotlib.pyplot as plt
import StringIO
# import os
# import opts
def processor(process, originalfile):
"""Main processor caller"""
# TODO Make a process number 'if' loop when we have different processes
result = processhed(originalfile, process)
return result
def processhed(imagefile, algorithm):
"""Process images with different algorithms"""
image = plt.imread(StringIO.StringIO(imagefile), format="JPG")
ihc_hed = rgb2hed(image)
if algorithm == '01':
result = plt.cm.gray(rescale_intensity(ihc_hed[:, :, 0],
out_range=(0, 1)))
elif algorithm == '02':
result = plt.cm.gray(rescale_intensity(ihc_hed[:, :, 1],
out_range=(0, 1)))
elif algorithm == '03':
result = plt.cm.gray(rescale_intensity(ihc_hed[:, :, 2],
out_range=(0, 1)))
else:
result = image
output = StringIO.StringIO()
plt.imsave(output, result, format="PNG")
contents = output.getvalue()
output.close()
return contents