コード例 #1
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.backimg = ips.backimg
         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 = 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.backmode = ips.backmode
     IPy.show_ips(ipsd)
コード例 #2
0
ファイル: result_plgs.py プロジェクト: Image-Py/seaice
 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)
コード例 #3
0
ファイル: shpio_plgs.py プロジェクト: pengguanjun/gistool
    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)
コード例 #4
0
ファイル: lifegame_plg.py プロジェクト: zhouchangSJTU/imagepy
 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)
コード例 #5
0
ファイル: shp_plgs.py プロジェクト: pengguanjun/gistool
 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)
コード例 #6
0
ファイル: shpio_plgs.py プロジェクト: pengguanjun/gistool
    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
コード例 #7
0
ファイル: shp_plgs_.py プロジェクト: xiaolingis/gistool
 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)
コード例 #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)
コード例 #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)
コード例 #10
0
ファイル: io_plgs.py プロジェクト: zemin-li/imagepy
 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)
コード例 #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)
コード例 #12
0
ファイル: lookuptables_plg.py プロジェクト: xsyp/imagepy
 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
コード例 #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)
コード例 #14
0
ファイル: raster_plgs.py プロジェクト: pengguanjun/gistool
 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)
コード例 #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)
コード例 #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)
コード例 #17
0
ファイル: raster_plgs.py プロジェクト: pengguanjun/gistool
    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)
コード例 #18
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) 
コード例 #19
0
ファイル: draw_plgs.py プロジェクト: xiaolingis/gistool
	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)
コード例 #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)
コード例 #21
0
    def run(self, ips, imgs, para=None):
        name = self.para['name']
        if ips.get_nslices() == 1 or self.para['stack'] == False:
            if ips.roi == None:
                img = ips.get_img().copy()
                ipsd = ImagePlus([img], name)
            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]))
        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]
            else:
                sc, sr = ips.get_rect()
                if ips.is3d: imgs = imgs[:, sc, sr].copy()
                else: imgs = [i[sc, sr].copy() for i in imgs]
            ipsd = ImagePlus(imgs, name)
            if ips.roi != None:
                ipsd.roi = ips.roi.affine(np.eye(2), (-sr.start, -sc.start))

        IPy.show_ips(ipsd)
コード例 #22
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