本文整理汇总了Python中ij.plugin.frame.RoiManager.reset方法的典型用法代码示例。如果您正苦于以下问题:Python RoiManager.reset方法的具体用法?Python RoiManager.reset怎么用?Python RoiManager.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.plugin.frame.RoiManager
的用法示例。
在下文中一共展示了RoiManager.reset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RoiManager
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import reset [as 别名]
ok = trackmate.process()
if not ok:
sys.exit(str(trackmate.getErrorMessage()))
#----------------
# Display results
#----------------
# The feature model, that stores edge and track features.
fm = model.getFeatureModel()
rm = RoiManager.getInstance()
if not rm:
rm = RoiManager()
rm.reset()
nextRoi = 0
for id in model.getTrackModel().trackIDs(True):
# Fetch the track feature from the feature model.
v = fm.getTrackFeature(id, 'TRACK_MEAN_SPEED')
v1 = fm.getTrackFeature(id, TrackBranchingAnalyzer.NUMBER_SPLITS)
if (v1>0):
model.getLogger().log('')
model.getLogger().log('Track ' + str(id) + ': branching = ' + str(v1))
track = model.getTrackModel().trackSpots(id)
sortedTrack = list( track )
Collections.sort( sortedTrack, Spot.frameComparator )
示例2: main
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import reset [as 别名]
def main():
# Get active dataset
#img = IJ.getImage()
display = displayservice.getActiveDisplay()
active_dataset = imagedisplayservice.getActiveDataset(display)
if not active_dataset:
IJ.showMessage('No image opened.')
return
# Get image path
fname = active_dataset.getSource()
dir_path = os.path.dirname(fname)
if not fname:
IJ.showMessage('Source image needs to match a file on the system.')
return
# Open ROIs
rois = RoiManager.getInstance()
if not rois:
roi_path = os.path.join(dir_path, "RoiSet.zip")
if not os.path.isfile(roi_path):
try:
roi_path = glob.glob(os.path.join(dir_path, "*.roi"))[0]
except:
roi_path = None
if not roi_path:
IJ.showMessage('No ROIs. Please use Analyze > Tools > ROI Manager...')
return
rois = RoiManager(True)
rois.reset()
rois.runCommand("Open", roi_path)
IJ.log('Image filename is %s' % fname)
dt = get_dt(active_dataset)
rois_array = rois.getRoisAsArray()
for i, roi in enumerate(rois_array):
crop_id = i + 1
IJ.log("Croping %i / %i" % (crop_id, len(rois_array)))
# Get filename and basename of the current cropped image
crop_basename = "crop%i_%s" % (crop_id, active_dataset.getName())
crop_basename = os.path.splitext(crop_basename)[0] + ".ome.tif"
crop_fname = os.path.join(os.path.dirname(fname), crop_basename)
# Get bounds and crop
bounds = roi.getBounds()
dataset = crop(ij, datasetservice, active_dataset,
bounds.x, bounds.y, bounds.width,
bounds.height, crop_basename)
# Show cropped image
ij.ui().show(dataset.getName(), dataset)
# Save cropped image (ugly hack)
IJ.log("Saving crop to %s" % crop_fname)
imp = IJ.getImage()
bfExporter = LociExporter()
macroOpts = "save=[" + crop_fname + "]"
bfExporter.setup(None, imp)
Macro.setOptions(macroOpts)
bfExporter.run(None)
imp.close()
IJ.log('Done')
示例3: segmentation
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import reset [as 别名]
def segmentation(imp, spot_data, channel, diameter_init, ES_tolerance, ES_area_max, ES_ctrl_pts, ES_iteration, repeat_max):
# Open files
cal = imp.getCalibration()
manager = RoiManager.getInstance()
if manager is None:
manager = RoiManager()
# Prepare log files for output
options = IS.MEDIAN | IS.AREA | IS.MIN_MAX | IS.CENTROID | IS.PERIMETER | IS.ELLIPSE | IS.SKEWNESS
convergence = []
Sintensity = []
for spot in spot_data:
repeat = 0
flag = False
spotID = int(spot[0])
Xcenter = (float(spot[1]) / cal.pixelWidth)
Ycenter = (float(spot[2]) / cal.pixelHeight)
Quality = float(spot[3])
diameter_init = float(spot[4] / cal.pixelWidth) * 2.0
while True:
manager = RoiManager.getInstance()
if manager is None:
manager = RoiManager()
Xcurrent = int(Xcenter - diameter_init / 2.0)
Ycurrent = int(Ycenter - diameter_init / 2.0)
Dcurrent1 = int(diameter_init * (1.2 - repeat / 10.0))
Dcurrent2 = int(diameter_init * (0.8 + repeat / 10.0))
roi = OvalRoi(Xcurrent, Ycurrent, Dcurrent1, Dcurrent2)
imp.setPosition(channel)
imp.setRoi(roi)
Esnake_options1 = "target_brightness=Bright control_points=" + \
str(ES_ctrl_pts) + " gaussian_blur=0 "
Esnake_options2 = "energy_type=Contour alpha=2.0E-5 max_iterations=" + \
str(ES_iteration) + " immortal=false"
IJ.run(imp, "E-Snake", Esnake_options1 + Esnake_options2)
roi_snake = manager.getRoisAsArray()
roi_ind = len(roi_snake) - 1
stats = IS.getStatistics(
imp.getProcessor(), options, imp.getCalibration())
perimeter = roi_snake[roi_ind].getLength() * cal.pixelWidth
circularity = 4.0 * 3.1417 * (stats.area / (perimeter * perimeter))
if stats.area > 17.0 and stats.area < ES_area_max and stats.skewness < -0.01 and circularity > 0.01 and stats.minor > 2.0 and boundaries(Xcenter, Ycenter, stats.xCentroid / cal.pixelWidth, stats.yCentroid / cal.pixelHeight, ES_tolerance):
Sintensity = stats.median
convergence.append(True)
break
if stats.median > 6000 and stats.area > 17.0 and stats.area < ES_area_max:
Sintensity = stats.median
convergence.append(True)
break
elif repeat > repeat_max:
manager.select(imp, roi_ind)
manager.runCommand(imp, 'Delete')
roi = OvalRoi(Xcenter + 1.0 - diameter_init / 2.0, Ycenter +
1.0 - diameter_init / 2.0, diameter_init, diameter_init)
imp.setRoi(roi)
manager.add(imp, roi, spotID)
roi_snake.append(roi)
stats = IS.getStatistics(
imp.getProcessor(), options, imp.getCalibration())
Sintensity = stats.median
convergence.append(False)
break
else:
IJ.log('Area=' + str(stats.area) + ' Skewness=' + str(stats.skewness) +
' circularity=' + str(circularity) + ' Minor=' + str(stats.minor))
manager.select(imp, roi_ind)
manager.runCommand(imp, 'Delete')
repeat += 1
# End Spot-segmentation
# End all Spots-segmentation
manager.runCommand(imp, 'Show All')
imp.setPosition(channel)
color = imp.createImagePlus()
ip = imp.getProcessor().duplicate()
color.setProcessor("segmentation" + str(channel), ip)
color.show()
IJ.selectWindow("segmentation" + str(channel))
manager.moveRoisToOverlay(color)
spot_optimal = manager.getRoisAsArray()
manager.reset()
for i in xrange(0, len(spot_optimal)):
spot = spot_optimal[i]
spot.setStrokeWidth(2)
if convergence[i]:
spot.setStrokeColor(Color.GREEN)
else:
spot.setStrokeColor(Color.MAGENTA)
imp.setRoi(spot)
manager.add(imp, spot, i)
manager.runCommand(imp, 'Show All')
imp.setPosition(channel)
示例4: channel_segmentation
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import reset [as 别名]
def channel_segmentation(infile, diameter, tolerance, repeat_max, Zrepeat=10):
# ROI optimization by Esnake optimisation
default_options = "stack_order=XYCZT color_mode=Grayscale view=Hyperstack"
IJ.run("Bio-Formats Importer", default_options + " open=[" + infile + "]")
imp = IJ.getImage()
cal = imp.getCalibration()
channels = [i for i in xrange(1, imp.getNChannels() + 1)]
log = filename(infile)
log = re.sub('.ids', '.csv', log)
XZdrift, YZdrift = retrieve_Zdrift(log)
XZpt = [i * imp.getWidth() / Zrepeat for i in xrange(1, Zrepeat - 1)]
YZpt = [i * imp.getHeight() / Zrepeat for i in xrange(1, Zrepeat - 1)]
# Prepare head output file
for ch in channels:
csv_name = 'ch' + str(ch) + log
with open(os.path.join(folder6, csv_name), 'wb') as outfile:
SegLog = csv.writer(outfile, delimiter=',')
SegLog.writerow(['spotID', 'Xpos', 'Ypos', 'Zpos',
'Quality', 'area', 'intensity', 'min', 'max', 'std'])
# Retrieve seeds from SpotDetector
options = IS.MEDIAN | IS.AREA | IS.MIN_MAX | IS.CENTROID
spots = retrieve_seeds(log)
for ch in channels:
for spot in spots:
repeat = 0
# Spots positions are given according to calibration, need to
# convert it to pixel coordinates
spotID = int(spot[0])
Xcenter = int(float(spot[2]) / cal.pixelWidth)
Ycenter = int(float(spot[3]) / cal.pixelHeight)
Zcenter = float(spot[4]) / cal.pixelDepth
Quality = float(spot[5])
# find closest grid location in Zdrift matrix
Xpt = min(range(len(XZpt)), key=lambda i: abs(XZpt[i] - Xcenter))
Ypt = min(range(len(YZpt)), key=lambda i: abs(YZpt[i] - Ycenter))
# Calculate Z position according to SpotZ, calibration and
# channel-specific Zdrift #
Zshift = median([float(XZdrift[Xpt][ch - 1]),
float(YZdrift[Ypt][ch - 1])]) / cal.pixelDepth
correctZ = int(Zcenter - Zshift)
imp.setPosition(ch, correctZ, 1)
imp.getProcessor().setMinAndMax(0, 3000)
while True:
manager = RoiManager.getInstance()
if manager is None:
manager = RoiManager()
roi = OvalRoi(Xcenter - diameter * (1.0 + repeat / 10.0) / 2.0, Ycenter - diameter * (
1.0 + repeat / 10.0) / 2.0, diameter * (1.0 + repeat / 10.0), diameter * (1.0 + repeat / 10.0))
imp.setRoi(roi)
IJ.run(imp, "E-Snake", "target_brightness=Bright control_points=3 gaussian_blur=0 energy_type=Mixture alpha=2.0E-5 max_iterations=20 immortal=false")
roi_snake = manager.getRoisAsArray()[0]
imp.setRoi(roi_snake)
stats = IS.getStatistics(
imp.getProcessor(), options, imp.getCalibration())
manager.reset()
if stats.area > 20.0 and stats.area < 150.0 and boundaries(Xcenter, Ycenter, stats.xCentroid / cal.pixelWidth, stats.yCentroid / cal.pixelHeight, tolerance):
Sarea = stats.area
Sintensity = stats.median
Smin = stats.min
Smax = stats.max
Sstd = stats.stdDev
break
elif repeat > repeat_max:
roi = OvalRoi(Xcenter - diameter / 2.0,
Ycenter - diameter / 2.0, diameter, diameter)
imp.setRoi(roi)
manager.add(imp, roi, i)
stats = IS.getStatistics(
imp.getProcessor(), options, imp.getCalibration())
Sarea = stats.area
Sintensity = stats.median
Smin = stats.min
Smax = stats.max
Sstd = stats.stdDev
break
else:
repeat += 1
# Save results
csv_name = 'ch' + str(ch) + log
with open(os.path.join(folder6, csv_name), 'ab') as outfile:
SegLog = csv.writer(outfile, delimiter=',')
SegLog.writerow([spotID, Xcenter, Ycenter, correctZ,
Quality, Sarea, Sintensity, Smin, Smax, Sstd])
# End spot optimization
# End spots
# End channels
IJ.selectWindow(filename(infile))
IJ.run("Close")