Skip to content

Commit 8cf9fca

Browse files
author
yxdragon
committed
lut
1 parent 86945cb commit 8cf9fca

File tree

7 files changed

+13
-60
lines changed

7 files changed

+13
-60
lines changed

imagepy/core/manager/colormanager.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,13 @@
1111
import sys
1212
from glob import glob
1313

14-
15-
16-
17-
# read from the lut binarycode
18-
# glob: return a list ot paths matching a pathname pattern.
1914
filenames = glob(os.path.join(root_dir,'data/luts/*.lut'))
15+
filenames.extend(glob(os.path.join(root_dir,'data/luts/*/*.lut')))
2016
keys = [os.path.split(filename)[-1][:-4] for filename in filenames]
2117
values = [np.fromfile(filename, dtype=np.uint8).reshape((3,256)).T.copy() for filename in filenames]
2218

23-
filenames_others = glob(os.path.join(root_dir,'data/luts/Others/*.lut'))
24-
keys_others = [os.path.split(filename)[-1][:-4] for filename in filenames_others]
25-
values_others = [np.fromfile(filename, dtype=np.uint8).reshape((3,256)).T.copy() for filename in filenames_others]
26-
2719
class ColorManager:
2820
luts = dict(zip(keys, values))
29-
luts_others = dict(zip(keys_others, values_others))
3021
frontcolor = (255,255,0)
3122
backcolor = (0,0,0)
3223
wr, wg, wb = 1.0/3, 1.0/3, 1.0/3
@@ -64,14 +55,8 @@ def get_back(cls, one):
6455
return np.dot((cls.wr,cls.wg,cls.wb), cls.backcolor)
6556

6657
@classmethod
67-
def get_lut(cls, name='grays'):
68-
if name=='grays':
69-
lut = np.arange(256).reshape((-1,1))
70-
return (lut*np.ones((1,3))).astype(np.uint8)
71-
else: return cls.luts[name].copy()
72-
@classmethod
73-
def get_lut_others(cls, name='grays'):
58+
def get_lut(cls, name='grays', set='all'):
7459
if name=='grays':
7560
lut = np.arange(256).reshape((-1,1))
7661
return (lut*np.ones((1,3))).astype(np.uint8)
77-
else: return cls.luts_others[name].copy()
62+
else: return cls.luts[name].copy()

imagepy/data/luts/Orange_Hot.lut

768 Bytes
Binary file not shown.

imagepy/data/luts/Red_Hot.lut

768 Bytes
Binary file not shown.

imagepy/data/luts/Yellow_Hot.lut

768 Bytes
Binary file not shown.

imagepy/menus/Image/Lookup table/Others/lookuptables_plg.py

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,9 @@
33
Created on Mon Oct 17 21:13:42 2016
44
@author: yxl
55
"""
6-
from imagepy import IPy
7-
import numpy as np
8-
from imagepy.core import ImagePlus
9-
from imagepy.ui.canvasframe import CanvasFrame
10-
from imagepy.core.engine import Free
11-
from imagepy.core.manager import ColorManager
6+
from imagepy import IPy, root_dir
7+
import os, glob
8+
from ..lookuptables_plg import Plugin
129

13-
class Plugin(Free):
14-
def __init__(self, key):
15-
self.title = key
16-
17-
def load(self):
18-
plus = IPy.get_ips()
19-
if plus==None:
20-
img = np.ones((30,1), dtype=np.uint8) * np.arange(256, dtype=np.uint8)
21-
ips = ImagePlus([img], self.title)
22-
ips.lut = ColorManager.get_lut_others(self.title)
23-
IPy.show_ips(ips)
24-
return False
25-
elif plus.channels != 1:
26-
IPy.alert('RGB image do not surport Lookup table!')
27-
return False
28-
return True
29-
30-
#process
31-
def run(self, para = None):
32-
plus = IPy.get_ips()
33-
plus.lut = ColorManager.get_lut_others(self.title)
34-
plus.update()
35-
36-
def __call__(self):
37-
return self
38-
39-
plgs = [Plugin(i) for i in list(ColorManager.luts_others.keys())]
40-
for i in range(len(plgs)):
41-
if plgs[i].title == 'Grays':
42-
plgs.insert(0, plgs.pop(i))
43-
44-
if __name__ == '__main__':
45-
print(list(ColorManager.luts_others.keys()))
46-
10+
fs = glob.glob(os.path.join(root_dir,'data/luts/Others/*.lut'))
11+
plgs = [Plugin(i) for i in [os.path.split(f)[-1][:-4] for f in fs]]

imagepy/menus/Image/Lookup table/lookuptables_plg.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
Created on Mon Oct 17 21:13:42 2016
44
@author: yxl
55
"""
6-
from imagepy import IPy
6+
from imagepy import IPy, root_dir
77
import numpy as np
88
from imagepy.core import ImagePlus
99
from imagepy.ui.canvasframe import CanvasFrame
1010
from imagepy.core.engine import Free
1111
from imagepy.core.manager import ColorManager
12+
import os, glob
1213

1314
class Plugin(Free):
1415
def __init__(self, key):
@@ -36,7 +37,9 @@ def run(self, para = None):
3637
def __call__(self):
3738
return self
3839

39-
plgs = [Plugin(i) for i in list(ColorManager.luts.keys())]
40+
fs = glob.glob(os.path.join(root_dir,'data/luts/*.lut'))
41+
plgs = [Plugin(i) for i in [os.path.split(f)[-1][:-4] for f in fs]]
42+
4043
for i in range(len(plgs)):
4144
if plgs[i].title == 'Grays':
4245
plgs.insert(0, plgs.pop(i))

0 commit comments

Comments
 (0)