def run(self, para=None):
        url = para['repo']
        if 'github.com' in url:
            if url[-4:] == '.git':
                url = url.replace('.git', '/archive/master.zip')
            elif url[-4:] != '.zip':
                url = url + '/archive/master.zip'
            domain, name = url.split('/')[-4:-2]
        else:
            domain, name = (url[:-4].replace('.', '-')).split('/')[-2:]
        domain, name = domain.replace('_', '-'), name.replace('_', '-')

        IPy.set_info('downloading plugin from %s' % para['repo'])
        urlretrieve(url,
                    os.path.join(path_cache, domain + '_' + name + '.zip'),
                    lambda a, b, c, p=self: Schedule(a, b, c, p))
        zipf = zipfile.ZipFile(
            os.path.join(path_cache, domain + '_' + name + '.zip'))
        folder = zipf.namelist()[0]
        zipf.extractall(path_cache)
        destpath = os.path.join(path_plgs,
                                domain + '_' + folder.replace('-master', ''))
        if os.path.exists(destpath): shutil.rmtree(destpath)
        os.rename(os.path.join(path_cache, folder), destpath)
        zipf.close()
        IPy.set_info('installing requirement liberies')
        self.prgs = (None, 1)
        cmds = [
            sys.executable, '-m', 'pip', 'install', '-r',
            '%s/requirements.txt' % destpath
        ]
        subprocess.call(cmds)
        IPy.reload_plgs(True, True, True, True)
示例#2
0
 def info(self, ips, cur):
     k, u = ips.unit
     l, r, t, b = self.lt, self.rt, self.tp, self.bm
     IPy.set_info('Rectangle : x:%.1f y:%.1f w:%.1f h:%.1f   S:%.1f' %
                  (min(l, r) * k, min(t, b) * k, abs(r - l) * k,
                   abs(b - t) * k, abs(
                       (r - l) * (b - t) / 4 * np.pi * k**2)))
示例#3
0
    def mouse_move(self, ips, x, y, btn, **key):
        if 'trans' in ips.data:
            trans = np.array(ips.data['trans']).reshape((2, 3))
            jw = np.dot(trans[:, 1:], (x, y)) + trans[:, 0]
            IPy.set_info('X:%d Y:%d ==> N:%.4f, E:%.4f' % (x, y, jw[0], jw[1]))

        if not 'adjc' in ips.data: return
        lim = 5.0 / key['canvas'].scale
        if btn == None:
            self.cursor = wx.CURSOR_CROSS
            ison = self.pick(x, y, ips.data['adjc'], lim)
            if ison != None:
                self.cursor = wx.CURSOR_HAND
        elif btn == 1:
            self.curobj[0], self.curobj[1] = x, y
            self.update(ips)
示例#4
0
    def runasyn(self, wb, info, key, para=None, callback=None):
        TaskManager.add(self)
        for i in para:
            if i in key and key[i][0] == 'img':
                ips = ImageManager.get(para[i])
                para[i] = ips if ips is None else ips.img

            if i in key and key[i][0] == 'tab':
                tps = TableManager.get(para[i])
                para[i] = tps if tps is None else tps.data

        start = time()
        xlreport.fill_value(wb, info, para)
        wb.save(para['path'])
        IPy.set_info('%s: cost %.3fs' % (self.title, time() - start))
        TaskManager.remove(self)
        if callback != None: callback()
示例#5
0
    def mouse_down(self, ips, x, y, btn, **key):
        if btn != 1: return
        msk = flood(ips.img, (int(y), int(x)), connectivity=0, tolerance=0)
        conts = find_contours(msk, 0.5, 'high')
        conts = conts[0][:, ::-1]
        ips.mark = Mark(conts)

        trans = ips.img.mat
        jw = np.dot(trans[:, 1:], conts.T).T + trans[:, 0]

        osrprj = osr.SpatialReference()
        osrprj.ImportFromWkt(ips.img.crs)
        osrgeo = osr.SpatialReference()
        osrgeo.ImportFromEPSG(3857)
        ct = osr.CoordinateTransformation(osrprj, osrgeo)

        xy = ct.TransformPoints(jw)
        polygon = Polygon(xy)
        c = polygon.centroid
        IPy.set_info('At N:%.4f, E:%.4f  Area:%.4f' % (c.x, c.y, polygon.area))
        ips.update()
示例#6
0
	def run(self, ips, imgs, para = None):
		k = para['diag']/np.sqrt((np.array(ips.img.shape)**2).sum())
		size = tuple((np.array(ips.img.shape)*k).astype(np.int16))
		IPy.set_info('down sample...')
		news = []
		for img in imgs:
			if k!=0: img = tf.resize(img, size)
			if para['sigma']!=0:
				img = ndimg.gaussian_filter(img, para['sigma'])
			news.append(img)

		IPy.set_info('register...')
		sr = StackReg(eval('StackReg.%s'%para['trans']))
		sr.register_stack(np.array(news), reference=para['ref'])

		mats = sr._tmats.reshape((sr._tmats.shape[0],-1))
		if k!=0: mats[:,[0,1,3,4,6,7]] *= k
		if k!=0: mats[:,[0,1,2,3,4,5]] /= k

		if para['tab']: IPy.show_table(pd.DataFrame(
			mats, columns=['A%d'%(i+1) for i in range(mats.shape[1])]), title='%s-Tmats'%ips.title)

		if para['new'] == 'None': return
		IPy.set_info('transform...')
		for i in range(sr._tmats.shape[0]):
			tform = tf.ProjectiveTransform(matrix=sr._tmats[i])
			img =  tf.warp(imgs[i], tform)
			img -= imgs[i].min(); img *= imgs[i].max() - imgs[i].min()
			if para['new'] == 'Inplace': imgs[i][:] = img
			if para['new'] == 'New': news[i] = img.astype(ips.img.dtype)
			self.progress(i, len(imgs))
		if para['new'] == 'New': IPy.show_img(news, '%s-reg'%ips.title)
示例#7
0
    def run(self, ips, imgs, para=None):
        lim = np.zeros([len(imgs), 2], dtype=imgs[0].dtype)
        dic = {np.uint8: 255, np.uint16: 65535, np.float32: 1, np.float64: 1}

        IPy.set_info('count range ...')
        for i in range(len(imgs)):
            lim[i] = imgs[i].min(), imgs[i].max()
            self.progress(i, len(imgs))

        maxvalue = dic[imgs[0].dtype.type]
        if not para['sb']: lim[:, 0] = 0
        rg = lim[:, 0].min(), lim[:, 1].max()
        if para['is3d']: lim[:] = rg
        IPy.set_info('adjust range ...')
        for i in range(len(imgs)):
            if para['sb']: imgs[i] -= lim[i, 0]
            np.multiply(imgs[i],
                        maxvalue / (lim[i].ptp()),
                        out=imgs[i],
                        casting='unsafe')
            self.progress(i, len(imgs))
        ips.range = 0, maxvalue
示例#8
0
 def on_mouseevent(self, me):
     tool = self.ips.tool
     if tool == None : tool = ToolsManager.curtool
     x,y = self.to_data_coor(me.GetX(), me.GetY())
     if me.Moving() and not me.LeftIsDown() and not me.RightIsDown() and not me.MiddleIsDown():
         xx,yy = int(round(x)), int(round(y))
         k, unit = self.ips.unit
         if xx>=0 and xx<self.ips.img.shape[1] and yy>=0 and yy<self.ips.img.shape[0]:
             IPy.set_info('Location:%.1f %.1f  Value:%s'%(x*k, y*k, self.ips.img[yy,xx]))
     if tool==None:return
     
     sta = [me.AltDown(), me.ControlDown(), me.ShiftDown()]
     if me.ButtonDown():tool.mouse_down(self.ips, x, y, me.GetButton(), alt=sta[0], ctrl=sta[1], shift=sta[2], canvas=self)
     if me.ButtonUp():tool.mouse_up(self.ips, x, y, me.GetButton(), alt=sta[0], ctrl=sta[1], shift=sta[2], canvas=self)
     if me.Moving():tool.mouse_move(self.ips, x, y, None, alt=sta[0], ctrl=sta[1], shift=sta[2], canvas=self)
     btn = [me.LeftIsDown(), me.MiddleIsDown(), me.RightIsDown(),True].index(True)
     if me.Dragging():tool.mouse_move(self.ips, x, y, 0 if btn==3 else btn+1, alt=sta[0], ctrl=sta[1], shift=sta[2], canvas=self)
     wheel = np.sign(me.GetWheelRotation())
     if wheel!=0:tool.mouse_wheel(self.ips, x, y, wheel, alt=sta[0], ctrl=sta[1], shift=sta[2], canvas=self)
     if hasattr(tool, 'cursor'):
         self.SetCursor(wx.Cursor(tool.cursor))
     else : self.SetCursor(wx.Cursor(wx.CURSOR_ARROW))
示例#9
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
示例#10
0
 def info(self, ips, cur):
     if cur == None: return
     IPy.set_info('Polygon: %.0f fragments' % len(self.body))
示例#11
0
 def info(self, ips, cur):
     k, u = ips.unit
     if cur==None:return
     x, y = self.body[cur]
     IPy.set_info('points:%.0f x:%.1f y:%.1f'%(len(self.body), x*k, y*k))
示例#12
0
 def mouse_move(self, ips, x, y, btn, **key):
     if not isinstance(ips.img, GeoArray):
         return IPy.set_info('No Coordinate')
     trans = ips.img.mat
     jw = np.dot(ips.img.mat[:, 1:], (x, y)) + ips.img.mat[:, 0]
     IPy.set_info('X:%d Y:%d ==> N:%.4f, E:%.4f' % (x, y, jw[0], jw[1]))
示例#13
0
	def run(self, para=None):
		IPy.set_info('update now, waiting...')
		repo = self.repo('../')
		client, remote_path = self.trans('https://github.com/Image-Py/imagepy.git')
		a = client.fetch(remote_path, repo)
		IPy.alert('imagepy update done!')
示例#14
0
文件: lineroi.py 项目: zhuzhs/imagepy
 def info(self, ips, cur):
     k, u = ips.unit
     if cur == None: return
     x, y = cur[0][cur[1]]
     IPy.set_info('Line : points:%.0f x:%.1f y:%.1f' %
                  (len(cur[0]), x * k, y * k))
示例#15
0
 def run(self, para=None):
     IPy.set_info('update now, waiting...')
     self.download_zip()
     self.deal_file()
     #self.delete_cache()
     IPy.alert('imagepy update done!')