def updatePointRoi(self): # Surround with try/except to prevent blocking # ImageJ's stack slice updater thread in case of error. try: # Update PointRoi self.imp.killRoi() point = self.nuclei[self.imp.getFrame()] # map 1-based slices # to 0-based nuclei Z coords if len(point) == 0: return IJ.log("Cell found in frame " + str(self.imp.getFrame())) # New empty PointRoi for the current slice roi = PointRoi(point[0], point[1]) # Style: large, red dots roi.setSize(4) # ranges 1-4 roi.setPointType(2) # 2 is a dot (filled circle) roi.setFillColor(Color.red) roi.setStrokeColor(Color.red) self.imp.setRoi(roi) except: IJ.error(sys.exc_info())
def findEndPoints(imageID, maskID): endPoints1 = [] endPoints2 = [] imp = IJ.getImage() imp.setSlice(1); roiManager = RoiManager.getInstance2() rois = roiManager.getRoisAsArray() roisToBeRemoved = [] index = 0 for roi in rois: outerBounds = roi.getBounds() impMT, innerBounds = duplicateMaskInRoi(imp, roi) nr, endPoint1, endPoint2 = findEndPointsInSkeleton(impMT) if (nr==2): endPoint1.x = endPoint1.x + outerBounds.x + innerBounds.x - 1 endPoint1.y = endPoint1.y + outerBounds.y + innerBounds.y - 1 endPoint2.x = endPoint2.x + outerBounds.x + innerBounds.x - 1 endPoint2.y = endPoint2.y + outerBounds.y + innerBounds.y - 1 endPoints1.append(endPoint1) endPoints2.append(endPoint2) else: roisToBeRemoved.append(index) impMT.close() index = index + 1 if (len(roisToBeRemoved)>0): roiManager.setSelectedIndexes(roisToBeRemoved) roiManager.runCommand("Delete") roiManager.moveRoisToOverlay(WindowManager.getImage(maskID)) inputIMP = WindowManager.getImage(imageID) inputIMP.setOverlay(PointRoi([seq.x for seq in endPoints1], [seq.y for seq in endPoints1]), Color.magenta, 1, Color.magenta) otherPoints = PointRoi([seq.x for seq in endPoints2], [seq.y for seq in endPoints2]) otherPoints.setStrokeColor(Color.cyan) otherPoints.setFillColor(Color.cyan) inputIMP.getOverlay().add(otherPoints)
def updatePointRoi(self): # Surround with try/except to prevent blocking # ImageJ's stack slice updater thread in case of error. try: # Update PointRoi self.imp.killRoi() points = self.nuclei[ self.imp.getSlice() - 1] # map 1-based slices to 0-based nuclei Z coords if 0 == len(points): IJ.log("No points for slice " + str(self.imp.getSlice())) return roi = PointRoi() # Style: large, red dots roi.setSize(4) # ranges 1-4 roi.setPointType(2) # 2 is a dot (filled circle) roi.setFillColor(Color.red) roi.setStrokeColor(Color.red) # Add points for point in points: # points are floats roi.addPoint(self.imp, int(point[0]), int(point[1])) self.imp.setRoi(roi) except: IJ.error(sys.exc_info())