Hi all! I am having some issues to calculate the area fraction form a Jyhton script. The idea is to load an image, generate some ROI’s across the image and calculate the area fraction inside each ROI and store that value into a table.
Apparently one can in Java you use List.setMeasurements and then
getValue(“Mean, Median, Feret, Area, etc.”) but i have not been able to make it work.
Below you can see my progress.
# Load 2D image od = OpenDialog("Choose a file", None) filename = od.getFileName() if filename is None: print "User canceled the dialog!" else: folder = od.getDirectory() filepath = folder + filename print "Selected file path:", filepath # Load the image into a ImagePlus object imp = IJ.openImage(os.path.join(folder, filename)) # Get imp processor ip = imp.getProcessor() # Create a table to store the results table = ResultsTable() # Create a ROI manager, to store each ROI (every cell) roiM = RoiManager(True) # We want to split the image e.g. into 4 sub ROI's # height and widht of the ROI nx=2 ny=2 w=imp.width/nx h=imp.height/ny # x,y values from the left corner # generate nx and ny ROI's across the image and store it into the ROImanager y=0 x=0 for i in xrange(nx): x=1.1*i*w for j in xrange(ny): y=1.1*j*h roi = Roi(x, y, w, h) roiM.addRoi(roi) # Here I want to print the area of the full image print "Full image ", imp.getStatistics().mean # Calculate the area fraction from each ROI for i in range(roiM.getCount()): roi = roiM.getRoi(i) imp.setRoi(roi) print "Cell i: ", i, " Cell j: ", j, imp.getStatistics() imp.show()``` Thanks! Mauro