def write_extraction_mask(self): """ write both the .roi file and the tif pages ROI file format specification: each row a ROI, first col: kw for roi type if circle: label, layer, pos x, pos y, diameter if poly: label, layer, pos x_1, pos_y1, ... pos x_n, pos y_n """ outpath = self.SaveFileDialog( title='saving ROIs', default_dir=self.Main.Options.general['cwd'], extension='*.roi') outpath = self.append_extension(outpath, '.roi') fh = open(outpath, 'w') # iterate over ROIs for i, ROI in enumerate(self.Main.ROIs.ROI_list): label = str(ROI.label) if type(ROI) == myCircleROI: # pos = sp.array([ROI.pos().x(),ROI.pos().y()]) # pos = self.get_ROI_position(ROI) x = str(sp.around(ROI.center[0], decimals=2)) y = str(sp.around(ROI.center[1], decimals=2)) d = str(sp.around(ROI.diameter, decimals=2)) fh.write('\t'.join(['circle', label, x, y, d, '\n'])) if type(ROI) == myPolyLineROI: fh.write('\t'.join(['polygon', label])) fh.write('\t') handle_pos = [tup[1] for tup in ROI.getSceneHandlePositions()] pos_mapped = [ROI.ViewBox.mapToView(pos) for pos in handle_pos] for pos in (pos_mapped): x = pos.x() y = pos.y() fh.write('\t'.join([ str(sp.around(x, decimals=2)), str(sp.around(y, decimals=2)) ])) fh.write('\t') fh.write('\n') fh.close() print "saved ROIs in .roi format to", outpath # outpath = os.path.splitext(outpath)[0] + '_mask.tif' # outpath = self.MainWindow.SaveFileDialog(title='saving ROIs',defaultdir=self.path,extension='.tif') # extraction mask self.Main.Processing.calc_extraction_mask() io.save_tstack(self.Main.Data.extraction_mask.astype('uint16'), os.path.splitext(outpath)[0] + '_mask.tif') print "saved ROIs in .tif format to", outpath pass
def write_extraction_mask(self): """ write both the .roi file and the tif pages ROI file format specification: each row a ROI, first col: kw for roi type if circle: label, layer, pos x, pos y, diameter if poly: label, layer, pos x_1, pos_y1, ... pos x_n, pos y_n """ outpath = self.SaveFileDialog(title='saving ROIs',default_dir = self.Main.Options.general['cwd'], extension='*.roi') outpath = self.append_extension(outpath, '.roi') fh = open(outpath,'w') # iterate over ROIs for i,ROI in enumerate(self.Main.ROIs.ROI_list): label = str(ROI.label) if type(ROI) == myCircleROI: # pos = sp.array([ROI.pos().x(),ROI.pos().y()]) # pos = self.get_ROI_position(ROI) x = str(sp.around(ROI.center[0],decimals=2)) y = str(sp.around(ROI.center[1],decimals=2)) d = str(sp.around(ROI.diameter,decimals=2)) fh.write('\t'.join(['circle',label,x,y,d,'\n'])) if type(ROI) == myPolyLineROI: fh.write('\t'.join(['polygon',label])) fh.write('\t') handle_pos = [tup[1] for tup in ROI.getSceneHandlePositions()] pos_mapped = [ROI.ViewBox.mapToView(pos) for pos in handle_pos] for pos in (pos_mapped): x = pos.x() y = pos.y() fh.write('\t'.join([str(sp.around(x,decimals=2)),str(sp.around(y,decimals=2))])) fh.write('\t') fh.write('\n') fh.close() print("saved ROIs in .roi format to", outpath) # outpath = os.path.splitext(outpath)[0] + '_mask.tif' # outpath = self.MainWindow.SaveFileDialog(title='saving ROIs',defaultdir=self.path,extension='.tif') # extraction mask self.Main.Processing.calc_extraction_mask() io.save_tstack(self.Main.Data.extraction_mask.astype('uint16'),os.path.splitext(outpath)[0] + '_mask.tif') print("saved ROIs in .tif format to", outpath) pass