Get Intensity Profile Across Multiple Line ROI

Hi everyone,

I’ve found a code to make multiple line ROI segments from a single drawn line. With all lines (~500) in the ROI Manager however, how do I make the intensity profile across all of these lines, the same way I would individually select each ROI & hit Ctrl+K (Analyze -> Plot Profile), and gather the data of each coordinate on that graph?

I should clarify that mean gray scale values and min/max values are not enough for the analysis that my team is doing. We really do need intensity values of every pixel across the ROI.

Thank you for your time!


If you have a bunch of lines in the ROIManager and would like to output all profiles to a single table you could try selecting all the ROIs and then using the multi-plot option under the more tab in the ROIManager. Alternatively if you want to script this then something like the following groovy script should work (although there is probably a simpler way :slight_smile: ):


// get current ROIManager and active image
#@ RoiManager rm
#@ ImagePlus imp

import ij.plugin.frame.RoiManager
import ij.measure.ResultsTable
import ij.gui.ProfilePlot

// create empty table
rt = new ResultsTable()

// fill empty cells of results table to NaN rather than zero

// loop through all rois
for (i = 0; i < rm.getCount(); i++) {
		// get roi line profile and add to results table
		profiler = new ProfilePlot(imp) 
		profile = profiler.getProfile()
		for (j = 0; j < profile.length; j++) 
			rt.setValue("line" + i, j, profile[j])

// show the profiles"line profiles")

Thank you so much for your response Jeremy! I wasn’t able to get the code working, however: an error message saying that a statement cannot begin with # came up. I did a bit of searching and figured this was some sort of parameter declaration, and is specified in the ImageJ Wiki, so it confuses me as to why it’s not recognizing its own syntax.

Alternatively, I did try the Multi-Plot tool, and I was able to get the data that I needed. It was strange, though… I’ve never been able to see all the profiles plotted like that.

I appreciate the help!