def mouse_down(self, ips, x, y, btn, **key): lim = 5.0 / key['canvas'].get_scale() if btn == 1 or btn == 3: if ips.roi != None: self.curobj = ips.roi.pick(x, y, lim) if not self.curobj in (None, True): return if ips.roi == None: msk = floodfill(ips.img, x, y, self.para['tor'], self.para['con'] == '8-connect') conts = find_contours(msk, 0, 'high') ips.roi = shape2roi(polygonize(conts, btn == 3)) elif hasattr(ips.roi, 'topolygon'): shp = roi2shape(ips.roi.topolygon()) oper = '' if key['shift']: oper = '+' elif key['ctrl']: oper = '-' elif self.curobj: return else: ips.roi = None msk = floodfill(ips.img, x, y, self.para['tor'], self.para['con'] == '8-connect') conts = find_contours(msk, 0, 'high') cur = polygonize(conts, btn == 3) if oper == '+': ips.roi = shape2roi(shp.union(cur)) elif oper == '-': ips.roi = shape2roi(shp.difference(cur)) else: ips.roi = shape2roi(cur) else: ips.roi = None ips.update()
def run(self, ips, imgs, para = None): gdf = gpd.read_file(para['path']).to_crs(ips.img.crs) m = ips.img.mat m = [1/m[0,1], 0, 0, 1/m[1,2], -m[0,0]/m[0,1], -m[1,0]/m[1,2]] shp = affine_transform(gdf['geometry'][0], m) ips.roi = convert.shape2roi(shp) if 'back' in ips.data:ips.roi.fill(ips.data['back'], (0,0,80))
def mouse_down(self, ips, x, y, btn, **key): lim = 5.0/key['canvas'].get_scale() if btn==1 or btn==3: if ips.roi!= None: self.curobj = ips.roi.pick(x, y, ips.cur, lim) ips.roi.info(ips, self.curobj) if not self.curobj in (None,True):return if ips.roi == None: connectivity=(self.para['con']=='8-connect')+1 img = ips.img.reshape((ips.img.shape+(1,))[:3]) msk = np.ones(img.shape[:2], dtype=np.bool) for i in range(img.shape[2]): msk &= flood(img[:,:,i], (int(y),int(x)), connectivity=connectivity, tolerance=self.para['tor']) conts = find_contours(msk, 0, 'high') ips.roi = shape2roi(polygonize(conts, btn==3)) elif hasattr(ips.roi, 'topolygon'): shp = roi2shape(ips.roi.topolygon()) oper = '' if key['shift']: oper = '+' elif key['ctrl']: oper = '-' elif self.curobj: return else: ips.roi=None connectivity=(self.para['con']=='8-connect')+1 img = ips.img.reshape((ips.img.shape+(1,))[:3]) msk = np.ones(img.shape[:2], dtype=np.bool) for i in range(img.shape[2]): msk &= flood(img[:,:,i], (int(y),int(x)), connectivity=connectivity, tolerance=self.para['tor']) conts = find_contours(msk, 0, 'high') cur = polygonize(conts, btn==3) if oper == '+': ips.roi = shape2roi(shp.union(cur)) elif oper == '-': ips.roi = shape2roi(shp.difference(cur)) else: ips.roi = shape2roi(cur) else: ips.roi = None ips.update()