00001 """Miscellaneous utilities for python interaction with ImageJ"""
00002 _rcsid="$Id: ImageJ_utilities.py,v 1.3 2003/05/30 13:31:54 mendenhall Release-20030716 $"
00003
00004 def read_ImageJ_measurement_file(file, maxlen=1000000):
00005 "Read a measurements file from ImageJ, and return a dictionary mapping columns names to numbers, a list of column names, and a table of the data provided"
00006 f=open(file,"r")
00007 strings=f.read(maxlen).split("\n")
00008 f.close()
00009 columns=[ [i.strip() for i in line.split("\t")] for line in strings if line]
00010 header=columns[0]
00011 keys={}
00012
00013 for i in range(1,len(header)):
00014 keys[header[i]]=i
00015 return keys, columns[0][1:], columns[1:]
00016
00017 def read_ImageJ_roi_file(file):
00018 "Read a measurements file from ImageJ containing (at least) the bounding rectangle information for a series of ROIs"
00019 keys, column_names, data = read_ImageJ_measurement_file(file)
00020 rois=[]
00021 column_map=[keys[name] for name in ("BX","BY","Width","Height")]
00022 for i in data[1:]:
00023 x0, y0, width, height= [int(i[c]) for c in column_map]
00024 rois.append([x0,y0,x0+width,y0+height])
00025 return rois
00026