Example #1
0
def decode_roi(roi_file):
    roi_obj = RoiDecoder(roi_file)
    x = roi_obj.getRoi().getPolygon().getBounds().x
    y = roi_obj.getRoi().getPolygon().getBounds().y
    width = roi_obj.getRoi().getPolygon().getBounds().width
    height = roi_obj.getRoi().getPolygon().getBounds().height
    return x, y, width, height
def roisFromFile(filePath):
	""" Get rois ROI[] from an roi file encoded by imagej """
	rois = []
	isZip = zipfile.is_zipfile(filePath)
	if isZip:
		print("It is a zip-file")
		zf = zipfile.ZipFile(filePath, 'r')
		print zf.namelist()
		for filename in zf.namelist():
			try:
				roiFile = zf.read(filename)
				rd = RoiDecoder(roiFile)
				roi = rd.getRoi()
				rois.append(roi)
			except KeyError:
				print 'ERROR: Did not find %s in zip file' % filename
	else:
		rd = RoiDecoder(filePath)
		rois.append(rd.getRoi())
	return(rois)