Exemplo n.º 1
0
 def run(self, para=None):
     first = generate(np.zeros((para['height'], para['width'])),
                      para['size'])
     imgs = [first.copy() for i in range(para['slice'])]
     ips = ImagePlus(imgs, para['name'])
     ips.tool = Painter(para['size'])
     IPy.show_ips(ips)
Exemplo n.º 2
0
    def run(self, para=None):
        if len(para['chans']) == 0: return
        #try:
        ds = gdal.Open(para['path'])
        sds = ds.GetSubDatasets()
        idx = [i[0] for i in sds]
        idx = [idx.index(i) for i in para['chans']]
        raster = geo_struct.read_hdf(para['path'], idx)
        #except:
        #    IPy.alert('unknown img format!')
        #    return

        files = self.getfiles(para['path'])
        files.sort()
        rasters = self.readimgs(
            files[para['start']:para['end'] + 1:para['step']], idx, raster)
        for i in range(len(idx)):
            imgs, ms, prjs = [], [], []
            for rs in rasters:
                imgs.append(rs.imgs[i])
                ms.append(rs.m)
                prjs.append(rs.prj)
            ips = ImagePlus(imgs, '%s-%s' % (para['title'], idx[i]))
            ips.data['trans'] = ms
            ips.data['prjs'] = prjs
            IPy.show_ips(ips)
Exemplo n.º 3
0
 def run(self, ips, imgs, para=None):
     name = para['name']
     print('name------------------', name)
     if ips.get_nslices() == 1 or self.para['stack'] == False:
         if ips.roi == None:
             img = ips.img.copy()
             ipsd = ImagePlus([img], name)
             ipsd.back = ips.back
         else:
             img = ips.get_subimg().copy()
             ipsd = ImagePlus([img], name)
             box = ips.roi.get_box()
             ipsd.roi = ips.roi.affine(np.eye(2), (-box[0], -box[1]))
             '''
             if not ips.backimg is None:
                 sr, sc = ips.get_rect()
                 ipsd.backimg = ips.backimg[sr, sc]
             '''
     elif ips.get_nslices() > 1 and self.para['stack']:
         if ips.roi == None:
             if ips.is3d: imgs = imgs.copy()
             else: imgs = [i.copy() for i in imgs]
             #backimg = ips.backimg
         else:
             sc, sr = ips.get_rect()
             if ips.is3d: imgs = imgs[:, sc, sr].copy()
             else: imgs = [i[sc, sr].copy() for i in imgs]
             #if not ips.backimg is None:
             #    backimg = None #ips.backimg[sr, sr]
         ipsd = ImagePlus(imgs, name)
         if ips.roi != None:
             ipsd.roi = ips.roi.affine(np.eye(2), (-sr.start, -sc.start))
         #if not ips.backimg is None: ipsd.backimg = backimg
     ipsd.chan_mode = ips.chan_mode
     IPy.show_ips(ipsd)
Exemplo n.º 4
0
 def run(self, tps, snap, data, para=None):
     raster = geo_util.shp2raster(data,
                                  para['scale'],
                                  margin=para['margin'],
                                  style='lab')
     ips = ImagePlus(raster.imgs, tps.title)
     ips.data['prj'], ips.data['trans'] = raster.prj, raster.m
     IPy.show_ips(ips)
Exemplo n.º 5
0
    def mouse_down(self, ips, x, y, btn, **key):
        if ips == self.ips1:
            self.ips1.mark.set_xy(x, y)
            self.ips.mark.set_xy(None, y)
            self.ips.cur = int(x)
            self.ips1.update()
            self.ips.update()
        elif ips == self.ips2:
            self.ips2.mark.set_xy(x, y)
            self.ips.mark.set_xy(x, None)
            self.ips.cur = int(y)
            self.ips2.update()
            self.ips.update()
        elif ips.get_nslices() == 1 or not ips.is3d:
            IPy.alert('stack required!')
            return
        elif self.view1 == None:
            img1, img2 = self.getimgs(ips.imgs, x, y)
            self.ips1 = ImagePlus([img1])
            self.ips2 = ImagePlus([img2])
            self.view1 = CanvasFrame(IPy.curapp)
            self.view2 = CanvasFrame(IPy.curapp)

            self.ips = ips
            self.view1.set_ips(self.ips1)
            self.view2.set_ips(self.ips2)
            canvas1, canvas2 = self.view1.canvas, self.view2.canvas
            canvas = IPy.get_window().canvas
            canvas1.scaleidx = canvas2.scaleidx = canvas.scaleidx
            canvas1.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            canvas2.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            self.view1.Show()
            self.view2.Show()
            ips.mark = Cross(*ips.size[::-1])
            ips.mark.set_xy(x, y)
            self.ips1.mark = Cross(*self.ips1.size[::-1])
            self.ips2.mark = Cross(*self.ips2.size[::-1])
            self.ips1.mark.set_xy(x, ips.cur)
            self.ips2.mark.set_xy(ips.cur, y)
            ips.update()

        else:
            img1, img2 = self.getimgs(ips.imgs, x, y)
            self.ips1.set_imgs([img1])
            self.ips2.set_imgs([img2])
            '''
            canvas1, canvas2 = self.view1.canvas, self.view2.canvas
            canvas = IPy.curwindow.canvas
            canvas1.scaleidx = canvas2.scaleidx = canvas.scaleidx
            canvas1.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            canvas2.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            '''
            self.ips1.mark.set_xy(ips.cur, y)
            self.ips2.mark.set_xy(x, ips.cur)
            self.ips1.update()
            self.ips2.update()
            ips.mark.set_xy(x, y)
            ips.update()
Exemplo n.º 6
0
    def run(self, para=None):
        fp, fn = osp.split(para['path'])
        fn, fe = osp.splitext(fn)
        raster = geo_struct.read_hdf(para['path'])
        ips = ImagePlus(raster.imgs, fn)
        IPy.show_ips(ips)

        ips.data['prj'] = raster.prj
        ips.data['trans'] = raster.m
Exemplo n.º 7
0
 def run(self, tps, snap, data, para=None):
     raster = geo_util.shp2raster(data,
                                  para['scale'],
                                  margin=para['margin'],
                                  value=para['value'],
                                  width=para['width'])
     ips = ImagePlus([raster[0]], tps.title)
     ips.data['prjs'], ips.data['trans'] = [raster[1]], [raster[2]]
     IPy.show_ips(ips)
Exemplo n.º 8
0
 def run(self, ips, imgs, para=None):
     if not para['slice']: imgs = [ips.img]
     shift = fftshift if para['shift'] else lambda x: x
     rst = []
     for i in range(len(imgs)):
         rst.append(shift(fft2(imgs[i])))
         self.progress(i, len(imgs))
     ips = ImagePlus(rst, '%s-fft' % ips.title)
     ips.log = True
     IPy.show_ips(ips)
Exemplo n.º 9
0
 def run(self, ips, imgs, para=None):
     r, g, b = ips.img.T
     cn1, cn3, cn4 = para['cn1'], para['cn3'], para['cn4']
     Av = (r * cn1 + b * cn3 + g * cn4).T
     Av = np.clip(Av, 0, 155).astype(np.uint8)
     img = gnp.geoarray(Av.astype(np.uint8),
                        mat=ips.img.mat,
                        crs=ips.img.crs)
     av_ips = ImagePlus([img], ips.title + '-Reflectivity')
     av_ips.data = ips.data
     IPy.show_ips(av_ips)
Exemplo n.º 10
0
 def run(self, ips, imgs, para = None):
     shp = ips.img.shape[:2]
     imgs = [np.zeros(shp, dtype=np.uint8) for i in range([1, len(imgs)][para['slice']])]
     newips = ImagePlus(imgs, ips.title+'-mark')
     newips.back = ips
     idx = ['None', 'Max', 'Min', 'Mask', '2-8mix', '4-6mix', '5-5mix', '6-4mix', '8-2mix']
     modes = ['set', 'max', 'min', 'msk', 0.2, 0.4, 0.5, 0.6, 0.8]
     newips.lut = ColorManager.get_lut(para['cm'])
     newips.chan_mode = modes[idx.index(para['mode'])]
     #newips.range = (0, para['n'])
     IPy.show_ips(newips)
Exemplo n.º 11
0
 def run(self, ips, imgs, para=None):
     ips1 = ImageManager.get(para['b1'])
     ips2 = ImageManager.get(para['b2'])
     rs1 = zip(ips1.imgs, ips1.data['prjs'], ips1.data['trans'])
     rs2 = zip(ips2.imgs, ips2.data['prjs'], ips2.data['trans'])
     rsts = []
     for r1, r2 in zip(rs1, rs2):
         rsts.append(geo_indicate.count_ndvi(r1, r2))
     imgs, prjs, trans = zip(*rsts)
     ips = ImagePlus(imgs, ips1.title + '-ndvi')
     ips.data['prjs'], ips.data['trans'] = prjs, trans
     IPy.show_ips(ips)
Exemplo n.º 12
0
 def load(self):
     plus = IPy.get_ips()
     if plus==None:
         img = np.ones((30,1), dtype=np.uint8) * np.arange(256, dtype=np.uint8)
         ips = ImagePlus([img], self.title)
         ips.lut = ColorManager.get_lut(self.title)
         IPy.show_ips(ips)
         return False
     elif plus.channels != 1:
         IPy.alert('RGB image do not surport Lookup table!')
         return False
     return True
Exemplo n.º 13
0
 def run(self, ips, imgs, para=None):
     if '/' in para['predictor']: path = para['predictor']
     else: path = self.root + '/' + para['predictor']
     model, key = joblib.load(path)
     if not para['slice']: imgs = [ips.img]
     slir, slic = ips.get_rect()
     imgs = [i[slir, slic] for i in imgs]
     rst = feature.get_predict(imgs, model, key, callback=self.progress)
     if rst is None:
         return IPy.alert('image channels dismatch this predictor!')
     ips = ImagePlus(rst, ips.title + '-mark')
     ips.range = ips.get_updown('all', 'one', step=512)
     IPy.show_ips(ips)
Exemplo n.º 14
0
 def run(self, ips, imgs, para=None):
     ips1 = ImageManager.get(para['b1'])
     ips2 = ImageManager.get(para['b2'])
     imgs = []
     for i in range(len(ips1.imgs)):
         b2, b1 = ips2.imgs[i], ips1.imgs[i]
         b1 = np.clip(b1, 1, 1e8, out=b1)
         b2 = np.clip(b2, 1, 1e8, out=b2)
         ndvi = (((b2 - b1) / (b2 + b1) + 1) / 2 * 255 + 0.5).astype(
             np.uint8)
         imgs.append(ndvi)
     ips = ImagePlus(imgs, ips1.title + '-ndvi')
     ips.data = ips1.data
     IPy.show_ips(ips)
Exemplo n.º 15
0
    def run(self, ips, imgs, para=None):
        if not ('prjs' in ips.data and 'trans' in ips.data):
            return IPy.alert('need projection and transform matrix!')
        objs = ImageManager.get(para['fragments'])
        if not ('prjs' in objs.data and 'trans' in objs.data):
            return IPy.alert('need projection and transform matrix!')
        goal = (imgs[0], ips.data['prjs'][0], ips.data['trans'][0])
        rasters = zip(objs.imgs, objs.data['prjs'], objs.data['trans'])

        rst = geo_util.rasters2des(list(rasters), goal, para['step'])

        ips = ImagePlus([rst[0]], ips.title + '-combine')
        ips.data['prjs'], ips.data['trans'] = [rst[1]], [rst[2]]
        IPy.show_ips(ips)
Exemplo n.º 16
0
    def run(self, ips, imgs, para=None):
        ndvi = ImageManager.get(para['ndvi'])
        lst = ImageManager.get(para['lst'])
        lab = ImageManager.get(para['lab'])
        area = ImageManager.get(para['area'])

        ndvi = list(zip(ndvi.imgs, ndvi.data['prjs'], ndvi.data['trans']))[0]
        lst = list(zip(lst.imgs, lst.data['prjs'], lst.data['trans']))[0]
        lab = list(zip(lab.imgs, lab.data['prjs'], lab.data['trans']))[0]
        area = list(zip(area.imgs, area.data['prjs'], area.data['trans']))[0]
        df = TableManager.get(para['df']).data
        rst = wheat.get_grade(ndvi, lst, lab, area, df)
        ips = ImagePlus([rst[0]], 'tiao xiu bing')
        ips.data['prjs'], ips.data['trans'] = [rst[1]], [rst[2]]
        IPy.show_ips(ips)
Exemplo n.º 17
0
    def run(self, ips, imgs, para=None):
        if not ('prj' in ips.data and 'trans' in ips.data):
            return IPy.alert('need projection and transform matrix!')
        objs = ImageManager.get(para['fragments'])
        if not ('prjs' in objs.data and 'trans' in objs.data):
            return IPy.alert('need projection and transform matrix!')

        goal = geo_struct.Raster(imgs, ips.data['prj'], ips.data['trans'])
        objs = zip(objs.imgs, objs.data['prjs'], objs.data['trans'])
        rasters = [geo_struct.Raster([i[0]], i[1], i[2]) for i in objs]
        rst = geo_util.rasters2one(rasters, goal, para['step'])

        ips = ImagePlus(rst.imgs, ips.title + '-combine')
        ips.data['prj'], ips.data['trans'] = goal.prj, goal.m
        IPy.show_ips(ips)
Exemplo n.º 18
0
 def run(self, ips, imgs, para=None):
     ips2 = ImageManager.get(para['temp'])
     nimg = ips.img * 0
     nimg[ips.img > 0] += 80
     nimg[ips2.img > 0] += 160
     ips = ImagePlus([nimg], ips.title + '-diff-' + ips2.title)
     IPy.show_ips(ips)
Exemplo n.º 19
0
    def run(self, ips, imgs, para = None):
        if not para['slice']:  imgs = [ips.img]
        print(para)
        labels = []
        for i in range(len(imgs)):
            self.progress(i, len(imgs))
            con = 1 if para['con']=='4-Connect' else 2
            idx = connect.connect_graph(imgs[i], con, para['back'])
            idx = connect.mapidx(idx)
            cmap = render.node_render(idx, para['colors'], 10)

            lut = np.ones(imgs[i].max()+1, dtype=np.uint8)
            lut[0] = 0
            for j in cmap: lut[j] = cmap[j]
            labels.append(lut[imgs[i]])

        ips = ImagePlus(labels, ips.title+'-render')
        ips.range = (0, para['colors'])
        IPy.show_ips(ips) 
Exemplo n.º 20
0
 def run(self, ips, imgs, para=None):
     if '/' in para['predictor']: path = para['predictor']
     else: path = self.root + '/' + para['predictor']
     model, key = joblib.load(path)
     lut = {
         'ori': 1,
         'blr': key['grade'],
         'sob': key['grade'],
         'eig': key['grade'] * 2
     }
     if sum([lut[i]
             for i in key['items']]) * ips.channels != len(key['titles']):
         return IPy.alert('image channels dismatch this predictor!')
     if not para['slice']: imgs = [ips.img]
     rst = []
     for i in range(len(imgs)):
         self.progress(i + 1, len(imgs))
         rst.append(get_predict(imgs[i], model, key))
     ips = ImagePlus(rst, ips.title + '-mark')
     ips.range = ips.get_updown('all', 'one', step=512)
     IPy.show_ips(ips)
Exemplo n.º 21
0
    def run(self, ips, imgs, para=None, preview=False):
        if len(ips.imgs) == 1: ips.img[:] = ips.snap
        key = {'chans': None, 'grade': para['grade'], 'w': para['w']}
        key['items'] = [i for i in ['ori', 'blr', 'sob', 'eig'] if para[i]]
        slir, slic = ips.get_rect()
        labs = [i[slir, slic] for i in imgs]
        ori = ImageManager.get(para['img']).imgs
        if len(imgs) == 1: ori = [ImageManager.get(para['img']).img]
        oris = [i[slir, slic] for i in ori]

        IPy.set_info('extract features...')
        feat, lab, key = feature.get_feature(oris,
                                             labs,
                                             key,
                                             callback=self.progress)

        IPy.set_info('training data...')
        self.progress(None, 1)
        model = self.classify(para)
        model.fit(feat, lab)

        IPy.set_info('predict data...')
        if preview:
            return feature.get_predict(oris,
                                       model,
                                       key,
                                       labs,
                                       callback=self.progress)
        if len(imgs) == 1: ips.swap()
        outs = feature.get_predict(oris, model, key, callback=self.progress)
        nips = ImagePlus(outs, ips.title + 'rst')
        nips.range, nips.lut = ips.range, ips.lut
        nips.back, nips.chan_mode = ips.back, 0.4
        IPy.show_ips(nips)
        global model_para
        model_para = model, key
Exemplo n.º 22
0
	def run(self, tps, snap, data, para=None):
		rsts = []
		dtype = {'8-bit':np.uint8, '16-bit':np.uint16}
		size = (para['width'], para['height'])
		if para['key'] == None:
			des = shp2raster(snap, size, para['margin'], 255, 0, dtype[para['type']])
			ips = ImagePlus([des[0]], tps.title)
			ips.data['prjs'], ips.data['trans'] = [des[1]], [des[2]]
			return IPy.show_ips(ips)
		index = snap[para['key']].unique()
		for i in range(len(index)):
			self.progress(i, len(index))
			prv = snap[snap[para['key']]==index[i]]
			des = shp2raster(prv, size, para['margin'], 255, 0, dtype[para['type']])
			rsts.append(des)
		imgs, prjs, ms = zip(*rsts)
		ips = ImagePlus(imgs, tps.title)
		ips.data['prjs'], ips.data['trans'] = prjs, ms
		IPy.show_ips(ips)
Exemplo n.º 23
0
class Orthogonal(Tool):
    title = 'Orthogonal View'

    def __init__(self):
        self.view1, self.view2 = None, None
        self.ips1, self.ips2 = None, None
        self.ips = None

    def getimgs(self, img, x, y):
        return img[:, :, int(x)].transpose((1,0,2)[:len(img.shape)-1]).copy(), \
            img[:, int(y), :].copy()

    def mouse_down(self, ips, x, y, btn, **key):
        if ips == self.ips1:
            self.ips1.mark.set_xy(x, y)
            self.ips.mark.set_xy(None, y)
            self.ips.cur = int(x)
            self.ips1.update()
            self.ips.update()
        elif ips == self.ips2:
            self.ips2.mark.set_xy(x, y)
            self.ips.mark.set_xy(x, None)
            self.ips.cur = int(y)
            self.ips2.update()
            self.ips.update()
        elif ips.get_nslices() == 1 or not ips.is3d:
            IPy.alert('stack required!')
            return
        elif self.view1 == None:
            img1, img2 = self.getimgs(ips.imgs, x, y)
            self.ips1 = ImagePlus([img1])
            self.ips2 = ImagePlus([img2])
            self.view1 = CanvasFrame(IPy.curapp)
            self.view2 = CanvasFrame(IPy.curapp)

            self.ips = ips
            self.view1.set_ips(self.ips1)
            self.view2.set_ips(self.ips2)
            canvas1, canvas2 = self.view1.canvas, self.view2.canvas
            canvas = IPy.get_window().canvas
            canvas1.scaleidx = canvas2.scaleidx = canvas.scaleidx
            canvas1.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            canvas2.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            self.view1.Show()
            self.view2.Show()
            ips.mark = Cross(*ips.size[::-1])
            ips.mark.set_xy(x, y)
            self.ips1.mark = Cross(*self.ips1.size[::-1])
            self.ips2.mark = Cross(*self.ips2.size[::-1])
            self.ips1.mark.set_xy(x, ips.cur)
            self.ips2.mark.set_xy(ips.cur, y)
            ips.update()

        else:
            img1, img2 = self.getimgs(ips.imgs, x, y)
            self.ips1.set_imgs([img1])
            self.ips2.set_imgs([img2])
            '''
            canvas1, canvas2 = self.view1.canvas, self.view2.canvas
            canvas = IPy.curwindow.canvas
            canvas1.scaleidx = canvas2.scaleidx = canvas.scaleidx
            canvas1.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            canvas2.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            '''
            self.ips1.mark.set_xy(ips.cur, y)
            self.ips2.mark.set_xy(x, ips.cur)
            self.ips1.update()
            self.ips2.update()
            ips.mark.set_xy(x, y)
            ips.update()

    def mouse_up(self, ips, x, y, btn, **key):
        pass

    def mouse_move(self, ips, x, y, btn, **key):
        if btn == 1:
            img1, img2 = self.getimgs(ips.imgs, x, y)
            self.ips1.set_imgs([img1])
            self.ips2.set_imgs([img2])
            self.ips1.update()
            self.ips2.update()
            ips.update()
            ips.mark.set_xy(x, y)

    def mouse_wheel(self, ips, x, y, d, **key):
        pass