Manging results with multimeasure and converting images to arrays

I am working on what should be a fairly simple macro in which I am to do a couple of things:

  1. Split a multi-channel image and background subtract each image, using a user-selected ROI (these get named “mRFP1” and “smURF”)
  2. Have the user draw ROIs around cells and add them to the ROI manager
  3. Use the multi-measure tool to measure the mean intensity in each ROI in each channel
  4. Take all of the pixels in each ROI and convert into a 2-column table, where each row is a single pixel in the ROI, and each column is the intensity of each channel for each pixel.

I’ve got steps 1 & 2 working well, but I cannot get step 3 to work as desired and do not know how to even start with step 4.

For Step 3 my current code is:

run("Set Measurements...", "mean redirect=None decimal=3");
setTool("freehand");
selectWindow("smURF");
waitForUser("Add cells to ROI manager, then press Okay to continue....");
roiManager("Measure");
selectWindow("mRFP1");
roiManager("Measure");

The issue I have is that this code puts the mRFP1 measurements after the smURF measurements - e.g. if I have 2 ROIs, the results from smURF are in rows 1&2, and the results from mRFP1 are in rows 3&4. What I want is for the results for the same ROI to appear on the same row, but in separate columns, in the result window. How do I do that?

And any advice on how to do step #4 is welcome.

Bryan

And, of course, I figured out how to do #3 immeidatly after posting this message. Still looking for help on #4.

Hi @BryanH,

Step 4 can be accomplished using this script:

tableName = "pixel values";
Table.create(tableName);

nr = roiManager("count");
for (i = 0; i < nr; i++) {
	selectWindow("smURF");
	roiManager("select", i);
	vs1 = getValues();
	
	selectWindow("mRFP1");
	roiManager("select", i);
	vs2 = getValues();
	
	dumpValues(vs1, vs2, tableName, i); // can also use Roi.getName instead of i
	}
	
run("Select None");

function dumpValues(vs1, vs2, tableName, roi){
	selectWindow(tableName);
	rowIndex = Table.size;
	for (i = 0; i < vs1.length; i++) {
		Table.set("roi", rowIndex + i, roi);
		Table.set("smURF", rowIndex + i, vs1[i]);
		Table.set("mRFP1", rowIndex + i, vs2[i]);
		}
	}
		
function getValues(){
	Roi.getContainedPoints(xpoints, ypoints);
	values=newArray(xpoints.length);

	for (i = 0; i < xpoints.length; i++) {
		values[i]=getPixel(xpoints[i], ypoints[i]);	
		}
	
	return values;
	}

Let me know if it works for you.

As a side note, listing pixel values of each roi does not sound like a good idea in general. What’s the goal? How are you going to process this information? can it be done within fiji (using the list of values, or better yet, by computing directly on the image) and then just list/plot the results?

Best,
Nico