def getXY(image): image.setC(2) pp = ProfilePlot(image).getPlot() pw = PlotWindow(image, pp) x, y = pw.getXValues(), pw.getYValues() # convert to java double for use in CurveFitter() class xd = [Double(i) for i in x] yd = [Double(i) for i in y] return xd, yd
def get_profile(imp, roi, rm): ''' Iteratively get the profile of each roi in a list from give img. returns ProfilePlots. ''' i = rm.getCount() rm.add(roi, i) roi.setName("{0}_{1}".format(imp.getTitle(), i)) rm.select(imp, i) pp = ProfilePlot(imp) return pp.getProfile()
def get_profile(imp, roi, rm): ''' Gets the profile plot of a roi from a given img. returns a list containing the measured intensities on each pixel. ''' from ij.gui import ProfilePlot i = rm.getCount() rm.add(roi, i) roi.setName("{0}_{1}".format(imp.getTitle(), i)) rm.select(imp, i) pp = ProfilePlot(imp) return pp.getProfile()
def saveProfile(nch, top, bottom, staining, genotype, staining_dir, image_name, cd=min_cd, cd_no=0, all_slices=False): if all_slices == True: temp_imp = IJ.getImage() top = temp_imp.NSlices bottom = 1 for j in range(bottom, top + 1): imp1 = IJ.getImage() imp1.setC(nch) imp1.setZ(j) pp1 = ProfilePlot(imp1) s = "profile" + str(j) exec(s + " = pp1.getProfile()") file_name = image_name[:( image_name.rfind('.tif'))] + "_" + staining + ".csv" file_save = staining_dir + file_name if cd == 1: with open(file_save, "w") as text_file: text_file.write("cd,cd_type,x,value") # text_file.close() with open(file_save, "a") as text_file: for j in range(len(eval("profile" + str(top)))): # print([profile1[j], profile2[j] ], max([profile1[j], profile2[j] ])) x = list() for k in range(bottom, top + 1): x.append(eval("profile" + str(k) + "[j]")) #print(x) if intensity_to_process == "max": text_file.write("\n" + str(cd) + "," + str(cd_no) + "," + str(j) + "," + str(max(x))) #print(len(x)) else: #print(int(len(x))) total = 0 for element in x: total = total + eval(element) text_file.write("\n" + str(cd) + "," + str(cd_no) + "," + str(j) + "," + str(total / len(x)))
def fit_gauss(lroi, imp, p, peak_id, id_, type_, rm): lroi.setName("{}_{}_{}".format(str(id_), peak_id, type_)) imp.setRoi(lroi) rm.addRoi(lroi) prof = ProfilePlot(imp) y = prof.getProfile() x = xrange(len(y)) fitter = CurveFitter(x, y) fitter.doFit(CurveFitter.GAUSSIAN) param_values = fitter.getParams() std = param_values[3] fwhm = 2.3548 * std r2 = fitter.getFitGoodness() y_ = [fitter.f(x_) for x_ in x] area_profile = sum(y) - len(y) *min(y) area_gauss = sum(y_) - len(y_)*min(y_) output = {} output["x_pos"] = p.x output["y_pos"] = p.y output["fwhm"] = fwhm output["fwhm_nm"] = pixel_size_nm * fwhm output["r2_GoF"] = r2 output["id"] = id_ output["peak_id"] = peak_id output["type"] = type_ # yai, excel maagic :-) output["avg_fwhm"] = '=AVERAGEIFS(F:F,B:B,B{},F:F,"<>"&"")'.format(id_+2) output["area_profile"] = area_profile output["area_gauss"] = area_gauss if peak_id == DEBUG: plot = Plot("ROI peak {} type {}".format(peak_id, type_), "X (gray)", "Y (fit window)") plot.setLineWidth(2) plot.setColor(Color.RED) plot.addPoints(x, y, Plot.LINE) plot.setColor(Color.BLUE) plot.addPoints(x, y_, Plot.LINE) plot.show() return output
# 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()