def generateOverlayRoi(self): """Generate the overlay ROI""" if (abs(self.p1[0] - self.p2[0]) ) > 800: # assume for now that lines run full length of image factor = 1024.0 / 800 loresp1x = int(round( self.p1[0] / factor)) - self.referenceRoiOffsetXY[0] loresp1y = int(round( self.p1[1] / factor)) - self.referenceRoiOffsetXY[1] loresp2x = int(round( self.p2[0] / factor)) - self.referenceRoiOffsetXY[0] loresp2y = int(round( self.p2[1] / factor)) - self.referenceRoiOffsetXY[1] #print([(loresp1x, loresp1y), (loresp2x,loresp2y)]); return Line(loresp1x, loresp1y, loresp2x, loresp2y) else: return Line(self.p1[0] - self.referenceRoiOffsetXY[0], self.p1[1] - self.referenceRoiOffsetXY[1], self.p2[0] - self.referenceRoiOffsetXY[0], self.p2[1] - self.referenceRoiOffsetXY[1])
def drawLines(imp, points=None): if points and (len(points) % 2 == 0): # points is numeric list of even length pRoi = PointRoi(points[0::2], points[1::2], len(points) / 2) pRoi.setShowLabels(True) pRoi.setSize(3) imp.setRoi(pRoi) roi = imp.getRoi() pp = roi.getFloatPolygon() # print "Added", pp.npoints if pp.npoints <= 1: # don't draw if only one point return xys = [] for i in xrange(pp.npoints): xys.append([pp.xpoints[i], pp.ypoints[i]]) ol = Overlay() x0 = xys[0][0] y0 = xys[0][1] cal = imp.getCalibration() for i in xrange(1, pp.npoints): xi = xys[i][0] yi = xys[i][1] # prepare text label d = math.sqrt((xi - x0)**2 + (yi - y0)**2) * cal.pixelWidth dText = String.format("%.2f ", d) + cal.getUnits() textOffset = 30 xt = xi yt = yi # if xi > x0: # xt += textOffset if xi < x0: xt -= textOffset # if yi > y0: # yt += textOffset if yi < y0: yt -= textOffset dTextRoi = TextRoi(xt, yt, dText) ol.add(dTextRoi) lineRoi = Line(x0, y0, xi, yi) lineRoi.setStrokeWidth(1) lineRoi.setStrokeColor(Color(255, 255, 0)) ol.add(lineRoi) imp.setOverlay(ol) imp.updateAndDraw()
egfp_imp.setZ(zidx + 1) cl_imp.setZ(zidx + 1) ip = cl_imp.getProcessor() out = MaximumFinder().getMaxima(ip, 10, True) centres.append((out.xpoints[0], out.ypoints[0])) centre = (out.xpoints[0], out.ypoints[0]) ring_roi_xs = [] ring_roi_ys = [] for theta in range(359): # for theta_idx in range(6): # theta = theta_idx * 60 - 90; pt1 = (centre[0] + min_r_pix * math.cos(math.radians(theta)), centre[1] + min_r_pix * math.sin(math.radians(theta))) pt2 = (centre[0] + max_r_pix * math.cos(math.radians(theta)), centre[1] + max_r_pix * math.sin(math.radians(theta))) roi = Line(pt1[0], pt1[1], pt2[0], pt2[1]) egfp_imp.setRoi(roi) profile = roi.getPixels() projected_im_row.append(max(profile)) try: ring_roi_xs.append(roi.getContainedPoints()[profile.index( max(profile))].x) except IndexError: ring_roi_xs.append(pt2[0]) try: ring_roi_ys.append(roi.getContainedPoints()[profile.index( max(profile))].y) except IndexError: ring_roi_ys.append(pt2[1]) #print("Max val = " + str(max(profile))); egfp_imp.killRoi()
from ij import IJ, WindowManager from ij.gui import Line IJ.run("Close All") imp = IJ.openImage("/Users/jrminter/Downloads/three_phase.jpeg") IJ.run(imp, "RGB to CIELAB", "") IJ.run("Stack to Images", "") imp_L = WindowManager.getImage("L") imp_a = WindowManager.getImage("a") imp_b = WindowManager.getImage("b") the_line = Line(0,178,690,178) the_line.setWidth(20) imp_L.setRoi(the_line) imp_L.show() IJ.run(imp_L, "Plot Profile", "") imp_a.setRoi(Line(0,231,690,220)) IJ.run(imp_a, "Plot Profile", "") imp_a.show()
def getEuclidean(self): """return the length of the straight line joining start and end points of the membrane""" poly = self.roi.getInterpolatedPolygon(1, True) line = Line(poly.xpoints[0], poly.ypoints[0], poly.xpoints[-1], poly.ypoints[-1]) return line.getLength()
# using a default generic RealType converter via t.setReal(t.getRealDouble()) compute(op).into(blurred, None, FloatType(), None) # Show the blurred image with the same LUT as the original imp2 = IL.wrap(blurred, "integral image radius 5 blur") imp2.getProcessor().setLut(imp.getProcessor().getLut()) imp2.show() # Compare with Gaussian blur from ij import ImagePlus from ij.plugin.filter import GaussianBlur from ij.gui import Line, ProfilePlot # Gaussian of the original image imp_gauss = ImagePlus(imp.getTitle() + " Gauss", imp.getProcessor().duplicate()) GaussianBlur().blurGaussian(imp_gauss.getProcessor(), radius) imp_gauss.show() # Plot values from a diagonal from bottom left to top right line = Line(imp.getWidth() - 1, 0, 0, imp.getHeight() - 1) imp_gauss.setRoi(line) pp1 = ProfilePlot(imp_gauss) plot = pp1.getPlot() imp2.setRoi(line) pp2 = ProfilePlot(imp2) profile2 = pp2.getProfile() # double[] plot.setColor("red") plot.add("line", range(len(profile2)), profile2) plot.show()
def do_angular_projection(imp, max_r_pix=60, min_r_pix=10, generate_roi_stack=True): """perform ray-based projection of vessel wall, c.f. ICY TubeSkinner (Lancino 2018)""" Prefs.blackBackground = True print("do angular projection input imp = " + str(imp)) split_chs = ChannelSplitter().split(imp) mch_imp = split_chs[0] IJ.setAutoThreshold(mch_imp, "IsoData dark stack") egfp_imp = split_chs[1] proj_imp = Duplicator().run(egfp_imp) cl_imp = split_chs[2] if generate_roi_stack: egfp_imp_disp = Duplicator().run(egfp_imp) roi_stack = IJ.createImage("rois", egfp_imp.getWidth(), egfp_imp.getHeight(), egfp_imp.getNSlices(), 16) centres = [] projected_im_pix = [] ring_rois = [] for zidx in range(cl_imp.getNSlices()): if ((zidx + 1) % 100) == 0: print("Progress = " + str(round(100 * (float(zidx + 1) / cl_imp.getNSlices())))) projected_im_row = [] proj_imp.setZ(zidx + 1) mch_imp.setZ(zidx + 1) bp = mch_imp.createThresholdMask() bp.dilate() bp.erode() bp.erode() bp.erode() mask_imp = ImagePlus("mask", bp) IJ.run(mask_imp, "Create Selection", "") roi = mask_imp.getRoi() proj_imp.setRoi(roi) IJ.run(proj_imp, "Set...", "value=0 slice") IJ.run(proj_imp, "Make Inverse", "") roi = proj_imp.getRoi() centre = (roi.getStatistics().xCentroid, roi.getStatistics().yCentroid) centres.append(centre) ring_roi_xs = [] ring_roi_ys = [] for theta in range(360): pt1 = (centre[0] + min_r_pix * math.cos(math.radians(theta)), centre[1] + min_r_pix * math.sin(math.radians(theta))) pt2 = (centre[0] + max_r_pix * math.cos(math.radians(theta)), centre[1] + max_r_pix * math.sin(math.radians(theta))) roi = Line(pt1[0], pt1[1], pt2[0], pt2[1]) proj_imp.setRoi(roi) profile = roi.getPixels() projected_im_row.append(max(profile)) try: ring_roi_xs.append(roi.getContainedPoints()[profile.index( max(profile))].x) except IndexError: ring_roi_xs.append(pt2[0]) try: ring_roi_ys.append(roi.getContainedPoints()[profile.index( max(profile))].y) except IndexError: ring_roi_ys.append(pt2[1]) proj_imp.killRoi() ring_roi = PolygonRoi(ring_roi_xs, ring_roi_ys, Roi.FREELINE) ring_rois.append(ring_roi) if generate_roi_stack: roi_stack.setZ(zidx + 1) roi_stack.setRoi(ring_roi) IJ.run(roi_stack, "Line to Area", "") IJ.run( roi_stack, "Set...", "value=" + str(roi_stack.getProcessor().maxValue()) + " slice") #egfp_imp.setRoi(ring_roi); projected_im_pix.append(projected_im_row) # for ch in split_chs: # ch.close(); out_imp = ImagePlus( "projected", FloatProcessor([list(x) for x in zip(*projected_im_pix)])) if generate_roi_stack: roi_stack.show() egfp_imp_disp.show() # merge? else: roi_stack = None return out_imp, roi_stack, ring_rois, centres
def getCells(dicStack): outStack = ImageStack(W,H) cells = [None for t in range(T+1)] for t in range(1,T+1): mapp = dicStack.getProcessor(t).convertToFloatProcessor() mapp.subtract( mapp.getStatistics().mean ) mapp.abs() RankFilters().rank(mapp, 1.0, RankFilters.VARIANCE) mapp.sqrt() mapp.blurGaussian(5) hist = mapp.getHistogram(256) stats = mapp.getStatistics() thresh = AutoThresholder().getThreshold( AutoThresholder.Method.Otsu, hist ) thresh = (thresh/float(255)) * (stats.max-stats.min) + stats.min mask = ByteProcessor(W,H) for i in range(W*H): value = mapp.getf(i) bite = 255 if value>=thresh else 0 mask.set(i, bite) fillHoles(mask) ed = 3 for e in range(ed): mask.erode(1, 0) for d in range(ed): mask.dilate(1, 0) watershed(mask) minA = 5000 #px² mask.setThreshold(255,255, ImageProcessor.NO_LUT_UPDATE) composite = ThresholdToSelection().convert(mask) rois = ShapeRoi(composite).getRois() keep = [] for roi in rois: if roi.getStatistics().area >= minA: if not onEdge(roi): keep.append(roi) else: edgeRoi = ShapeRoi(roi) edgeRoi.setPosition(0,0,t) edgeRoi.setStrokeColor(Color.YELLOW) ol.add(edgeRoi) print("T"+str(t)+" using "+str(len(keep))+"/"+str(len(rois))+" ROIs") rois = keep #rois = [ roi for roi in rois if roi.getStatistics().area >= minA and not onEdge(roi) ] #keep big enough and not on edges # if there is only one Roi, cut it along the fitted ellipse minor axis if len(rois)==1: el = EllipseFitter() mask.setRoi(rois[0]) el.fit(mask, None) el.makeRoi(mask) theta = el.angle * (maths.pi/180.0) length = el.major/2.0 dy = maths.sin(theta)* length dx = maths.cos(theta)* length #major axis lineX0 = el.xCenter - dx lineY0 = el.yCenter + dy lineX1 = el.xCenter + dx lineY1 = el.yCenter - dy line = Line(lineX0, lineY0, lineX1, lineY1) line.setStrokeColor(Color.BLUE) line.setStrokeWidth(1) line.setPosition(0,0,t) ol.add(line) #minor axis scaled length to make sure cut ends are outside Roi cutX0 = el.xCenter + dy*100 cutY0 = el.xCenter + dx*100 cutX1 = el.yCenter - dy*100 cutY1 = el.yCenter - dx*100 cut = Line(cutX0,cutY0, cutX1, cutY1) cut.setStrokeWidth(2) cut = PolygonRoi( cut.getFloatPolygon(), PolygonRoi.POLYGON ) mask.setColor(0) mask.fill(cut) composite = ThresholdToSelection().convert(mask) rois = ShapeRoi(composite).getRois() rois = [ roi for roi in rois if roi.getStatistics().area >= minA ] print(str(t) + ":" + str(len(rois))) rois = [ PolygonRoi(roi.getInterpolatedPolygon(20, True), PolygonRoi.POLYGON) for roi in rois ] rois = [ PolygonRoi(roi.getConvexHull(), PolygonRoi.POLYGON) for roi in rois ] rois = sorted(list(rois), key=lambda roi:roi.getLength() ) #size order rois = rois[-2:] #keep 2 biggest rois = sorted(list(rois), key=lambda roi:roi.getStatistics().xCentroid+roi.getStatistics().yCentroid ) #top left to bottom right order if len(rois)>0: rois[0].setStrokeColor(Color.RED) rois[0].setPosition(0, 0, t) ol.add(rois[0]) if len(rois)>1: rois[1].setStrokeColor(Color.GREEN) rois[1].setPosition(0, 0, t) ol.add(rois[1]) cells[t] = (rois[0], rois[1]) return cells
for l in range(0, height): for c in range(l + 1, width): p1 = pointList[l] p2 = pointList[c] delta_x = p1.x - p2.x delta_y = p1.y - p2.y value = math.sqrt((delta_x * delta_x) + (delta_y * delta_y)) matrix[l][c] = value matrix[c][l] = value nearestNeighborsDist = [] nearestNeighborsInd = [] for l in range(0, width): minimum = min(matrix[l]) index = matrix[l].index(minimum) nearestNeighborsDist.append(minimum) nearestNeighborsInd.append(index) RoiManager() roiManager = RoiManager.getRoiManager() for i in range(0, width): nnI = nearestNeighborsInd[i] if (nnI < i and nearestNeighborsInd[nnI] == i): continue p1 = pointList[i] p2 = pointList[nnI] roi = Line(p1.x, p1.y, p2.x, p2.y) roiManager.addRoi(roi)
def makeArrow(x1, y1, x2, y2): IJ.setTool("arrow") imp = IJ.getImage() imp.setRoi(Line(x1, y1, x2, y2))
def main(imp,options): from ij.plugin import ChannelSplitter from ij.gui import Roi,PointRoi, PolygonRoi, Overlay, Line from java.awt import Color from ij import WindowManager from ij.measure import ResultsTable from ij.text import TextWindow active_z=imp.getZ() imps = ChannelSplitter.split(imp) imp.setZ(active_z) roi_int = imp.getRoi() comp_imp=Zproj(imps[options["comp_ch"]], "SUM", active_z, options["z_range"]) comp_imp=mode_subtract(comp_imp,roi_int) loci_imp=Zproj(imps[options["loci_ch"]], "SUM", imp.getZ(), options["z_range"]) loci_imp=mode_subtract(loci_imp,roi_int) #Finding the boundaries of compartment and loci comp_roi=thresh(sum_prj=comp_imp,thresh=options["comp_T"],roi=roi_int,method="boundary") print "ok" if (options["loci_method"]== "locus center"): loci_roi=thresh(sum_prj=loci_imp, thresh=options["loci_T"], roi=roi_int, method="point") elif options["loci_method"]== "locus boundary": loci_roi=thresh(sum_prj=loci_imp, thresh=options["loci_T"], roi=roi_int, method="boundary") if options["loci_method"]== "locus center": dist,xc,yc,xl,yl=get_center_edge_dist(imp,comp_roi, loci_roi) elif options["loci_method"]== "locus boundary": dist,xc,yc,xl,yl=get_closest_points(imp,comp_roi,loci_roi) rt_exist = WindowManager.getWindow("Loci distance to compartment") if rt_exist==None or not isinstance(rt_exist, TextWindow): table= ResultsTable() else: table = rt_exist.getTextPanel().getOrCreateResultsTable() table.incrementCounter() table.addValue("Label", imp.title) table.addValue("Distance(micron)", dist) if options['measure_feret']: feret_roi,loci_feret,loci_area= feret(sum_prj=loci_imp,thresh=options["loci_T"], roi=roi_int,pixel_size=imp.getCalibration().pixelWidth) table.addValue("Loci feret", loci_feret) table.addValue("Loci area", loci_area) table.show("Loci distance to compartment") ## Adding loci overlay ov=imp.getOverlay() if ov==None: ov=Overlay() line = Line(xc,yc, xl,yl) line.setStrokeWidth(0.2) line.setStrokeColor(Color.PINK) ov.add(line) if options["loci_method"]== "locus center": ov.add(PointRoi(loci_roi["x"],loci_roi["y"])) elif options["loci_method"]== "locus boundary": ov.add(loci_roi) if options['measure_feret']: ov.add(feret_roi) ov.add(comp_roi) imp.setOverlay(ov)
def batch_open_images(pathImage, file_typeImage, name_filterImage=None): if isinstance(pathImage, File): pathImage = pathImage.getAbsolutePath() def check_filter(string): '''This function is used to check for a given filter. It is possible to use a single string or a list/tuple of strings as filter. This function can access the variables of the surrounding function. :param string: The filename to perform the filtering on. ''' if name_filterImage: # The first branch is used if name_filter is a list or a tuple. if isinstance(name_filterImage, (list, tuple)): for name_filter_ in name_filterImage: if name_filter_ in string: # Exit the function with True. return True else: # Next iteration of the for loop. continue # The second branch is used if name_filter is a string. elif isinstance(name_filterImage, string): if name_filterImage in string: return True else: return False return False else: # Accept all files if name_filter is None. return True def check_type(string): '''This function is used to check the file type. It is possible to use a single string or a list/tuple of strings as filter. This function can access the variables of the surrounding function. :param string: The filename to perform the check on. ''' if file_typeImage: # The first branch is used if file_type is a list or a tuple. if isinstance(file_typeImage, (list, tuple)): for file_type_ in file_typeImage: if string.endswith(file_type_): # Exit the function with True. return True else: # Next iteration of the for loop. continue # The second branch is used if file_type is a string. elif isinstance(file_typeImage, string): if string.endswith(file_typeImage): return True else: return False return False # Accept all files if file_type is None. else: return True # We collect all files to open in a list. path_to_Image = [] # Replacing some abbreviations (e.g. $HOME on Linux). path = os.path.expanduser(pathImage) path = os.path.expandvars(pathImage) # If we don't want a recursive search, we can use os.listdir(). for directory, dir_names, file_names in os.walk(pathImage): # We are only interested in files. for file_name in file_names: # The list contains only the file names. # The full path needs to be reconstructed. full_path = os.path.join(directory, file_name) # Both checks are performed to filter the files. if check_type(file_name): if check_filter(file_name) is False: # Add the file to the list of images to open. path_to_Image.append([ full_path, os.path.basename(os.path.splitext(full_path)[0]) ]) Images = [] for img_path, file_name in path_to_Image: imp = IJ.openImage(img_path) maskimage = ops.run("create.img", imp) cursor = maskimage.localizingCursor() imp.show() IJ.run("Select None") overlay = imp.getOverlay() if overlay == None: overlay = Overlay() imp.setOverlay(overlay) else: overlay.clear() imp.updateAndDraw() impY = imp.getHeight() impX = imp.getWidth() print(impY, impX) rm = RoiManager.getInstance() if not rm: rm = RoiManager() rm.runCommand("reset") WaitForUserDialog("Select the landmark and the second point").show() rm.runCommand("Add") roi_points = rm.getRoisAsArray() for Roi in roi_points: xpoints = Roi.getPolygon().xpoints ypoints = Roi.getPolygon().ypoints print(xpoints, ypoints) print('Start Landmark', xpoints[0], ypoints[0]) fixedpointX = xpoints[0] fixedpointY = ypoints[0] print('End Landmark', xpoints[1], ypoints[1]) IJ.makeLine(xpoints[0], ypoints[0], xpoints[1], ypoints[1]) gui = GenericDialog("Rotation Angle") gui.addNumericField("Choose Angle", 15, 0) gui.showDialog() if gui.wasOKed(): rotateangle = gui.getNextNumber() IJ.run("Rotate...", "angle=" + str(int(float(rotateangle)))) rm.runCommand("reset") overlay = imp.getOverlay() rm.runCommand("Add") roi_points = rm.getRoisAsArray() for Roi in roi_points: xpoints = Roi.getPolygon().xpoints ypoints = Roi.getPolygon().ypoints print(xpoints, ypoints) print('Rotated Start Landmark', xpoints[0], ypoints[0]) print('Rotated End Landmark', xpoints[1], ypoints[1]) slope = (ypoints[1] - ypoints[0]) / (xpoints[1] - xpoints[0] + 1.0E-20) intercept = fixedpointY - slope * fixedpointX print(fixedpointX, fixedpointY) print('Slope', slope, 'Intercept', intercept) XwY0 = -intercept / slope YxwY0 = slope * XwY0 + intercept XwYmax = (impY - intercept) / slope YxwYmax = slope * XwYmax + intercept YwX0 = intercept XywX0 = (YwX0 - intercept) / slope YwXmax = impX * slope + intercept XxwXmax = (YwXmax - intercept) / slope rm.runCommand("reset") if XwY0 > 0: lineROIA = Line(fixedpointX, fixedpointY, XwY0, YxwY0) lineROIB = Line(fixedpointX, fixedpointY, XwYmax, YxwYmax) overlay.add(lineROIA) overlay.add(lineROIB) if XwY0 < 0: lineROIA = Line(fixedpointX, fixedpointY, XywX0, YwX0) lineROIB = Line(fixedpointX, fixedpointY, XxwXmax, YwXmax) overlay.add(lineROIA) overlay.add(lineROIB) while cursor.hasNext(): cursor.fwd() X = cursor.getDoublePosition(0) Y = cursor.getDoublePosition(1) if abs(Y - slope * X - intercept) <= 4: cursor.get().set(0) else: cursor.get().set(1) labeling = ops.labeling().cca(maskimage, StructuringElement.EIGHT_CONNECTED) # get the index image (each object will have a unique gray level) labelingIndex = labeling.getIndexImg() dataImg = ds.create(labelingIndex) location = ls.resolve( str(savedir) + '/' + file_name + '.' + file_type_image) dio.save(dataImg, location) imp.close()
for bp in brightestpixellist: x = bp%imp.width y = bp/imp.width #print "max. brightness coordinates:", x, y # note that the following chooses for x, y the last element in the brightestpixelist which is OK if there is only one element # TODO: would be nicer to loop over this list or specify which element to pick length = 400/2 angular_accuracy = 5 # degrees for alpha in range(0, 180, angular_accuracy): myimp = ImagePlus("Profile_"+str(alpha), ip) vecx, vecy = length * cos(alpha * pi/180), length * sin(alpha * pi/180) roi = Line(x-vecx, y-vecy, x+vecx, y+vecy) myimp.setRoi(roi) #ip.draw(roi) # enabling this creates artifacts - careful! # create ProfilePlot profplot = ProfilePlot(myimp) #profplot.createWindow() # enabling this creates a nice animation #print alpha, sum(profplot.getProfile())/len(profplot.getProfile()) # test: average of profile values as proxy for brightness # get the data profarray = profplot.getProfile() # smooth the data by calculating moving average win = 12 # window size for moving average, must be even movavg = moving_average(profarray, win) medi = median(movavg)
def main(imp, tolerance, window_radius, pixel_size_nm, out_dir): # set output dir out_dir = str(out_dir) # Find maxima excludeOnEdge = True polygon = MaximumFinder().getMaxima(imp.getProcessor(), tolerance, excludeOnEdge) roi = PointRoi(polygon) # get RoiManager rm = RoiManager.getInstance(); if rm is None: rm = RoiManager() # Check if output table is writable out_table_fn = os.path.join(out_dir, "fwhm_values.txt") try: file_handle = open(out_table_fn, 'w') except IOError: IJ.showMessage("Output file '' not writeable. Check if file is open in Excel...") sys.exit(0) # iterate and write output with file_handle as csvfile: writer = csv.DictWriter(csvfile, fieldnames=["id", "peak_id", "x_pos", "y_pos", "type", "fwhm", "fwhm_nm", "r2_GoF", "avg_fwhm", "area_profile", "area_gauss"], delimiter="\t", lineterminator='\n') writer.writeheader() id_ = 0 # over all peaks for i, p in list(enumerate(roi)): IJ.showProgress(i, roi.getNCounters() +1) # Horizontal lroi = Line(p.x+0.5-window_radius, p.y+0.5, p.x+0.5+window_radius, p.y+0.5) output = fit_gauss(lroi, imp, p, i, id_, "H", rm) writer.writerow(output) id_+=1 # Vertical lroi = Line(p.x+0.5, p.y+0.5-window_radius, p.x+0.5, p.y+0.5+window_radius) output = fit_gauss(lroi, imp, p, i, id_, "V", rm) writer.writerow(output) id_+=1 # Diagonal 1 lroi = Line(p.x+0.5-MN*window_radius, p.y+0.5+MN*window_radius, p.x+0.5+MN*window_radius, p.y+0.5-MN*window_radius) output = fit_gauss(lroi, imp, p, i, id_, "D1", rm) writer.writerow(output) id_+=1 # Diagonal 2 lroi = Line(p.x+0.5-MN*window_radius, p.y+0.5-MN*window_radius, p.x+0.5+MN*window_radius, p.y+0.5+MN*window_radius) output = fit_gauss(lroi, imp, p, i, id_, "D2", rm) writer.writerow(output) id_+=1 IJ.showProgress(1) rm.runCommand("Deselect"); # deselect ROIs to save them all rm.runCommand("Save", os.path.join(out_dir, "fwhm_fiji_rois.zip")) IJ.showMessage("FWHM on Spots: Done")
def angle(xy1, xy2): diffx = xy2[0] - xy1[0] diffy = xy2[1] - xy1[1] return math.atan2(diffy, diffx) def calculate_point(x_orig, y_orig, distance, angle): x_new = distance * math.cos(math.radians(angle)) + x_orig y_new = (distance * math.sin(math.radians(angle)) - y_orig) * -1 return (x_new, y_new) # Defining the boxes roi1 = Line(point1[0], point1[1], point2[0], point2[1]) upangle = roi1.getAngle() + 90 downangle = roi1.getAngle() - 90 distance = roi1.getLength() / pixelsize # calculating the coordinates of the box ROIs starting_upper_point = (calculate_point(point1[0], point1[1], roi_width, upangle)) starting_lower_point = (calculate_point(point1[0], point1[1], roi_width, downangle)) end_upper_point = (calculate_point(point2[0], point2[1], roi_width, roi1.getAngle() + 90)) end_lower_point = (calculate_point(point2[0], point2[1], roi_width,