Extract results from ResultTable for different channels

jython
imagej
results-table

#1

Hello everybody,

I have a problem with the handling of ResultsTable for the measurements of different parameters in different channels. I have a timeframe stack composed of different channels. What I do is to extract the channel, segment the nuclei for one channel and measure their shape, then use the rois to measure the mean intensity in the other channel, so that to be able to to trace back for the same cell the intensity in the other channels and its dimensions.

The problem is that if I try to extract the result of the measured intensity for one channel, it writes the shape measurements, while another result table opens with the measurements I want. How can I refer to the new ResultTable?

Here is my function

def iterate(imp, path_cyan, path_venus, path_cherry):
	"""Iterate through timeframes to process images"""
	mcherry = extractChannel(imp,2)
	venus = extractChannel(imp,3)
	mask_cyan = extractChannel(imp,4)
	BlurImage(mask_cyan, 2.0, 1.0)  
	IJ.run(mask_cyan, "Subtract Background...", "rolling=30 sliding stack")
	IJ.run(mask_cyan,"Convert to Mask", "method=Li background=Dark calculate")
	IJ.run(mask_cyan, "Watershed", "stack")
	
	rm = RoiManager().getInstance() #select the roi
	table, p = segmentParameters(mask_cyan)
	for i in range(mask_cyan.getStackSize()): 
		mask_cyan.setSliceWithoutUpdate(i + 1)
		if p.analyze(mask_cyan):
			print "All ok: "+ str(i+1)
		else:
			print "There was a problem in analyzing", mask_cyan
		for roi in range(0, rm.getCount()):
			rm.select(roi)
			result = "Frame: "+str(i+1)+"\t"+table.getRowAsString(roi)+"\n"
			path_cyan.write(result)
			
		#table.reset()
		
		mcherry.setSliceWithoutUpdate(i + 1)
		mcherry.show()

		for roi in range(0, rm.getCount()):
			rm.select(roi)
			rm.runCommand("Measure")
			result = table.getRowAsString(roi)+"\n"
			path_cherry.write(result)

		venus.setSliceWithoutUpdate(i + 1)
		venus.show()

		for roi in range(0, rm.getCount()):
			rm.select(roi)
			rm.translate(-5,5)
			rm.runCommand("Measure")
			result = table.getRowAsString(roi)+"\n"
			path_venus.write(result)
	#problema:table refers to the rt where I have cyan´s results. How can I refer it to the new rt?
		rm.runCommand("Select All"); rm.runCommand("Delete")

I am writing in Jython, so I would really appreciate a help in this programming language :slight_smile:


#2

Without seeing the whole code:

You can rename the tables and then reference them to store the individual results. Here an example:

#author: M. Austenfeld
from ij import IJ;
from ij import WindowManager;

imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
imp.show();
imp.setRoi(50,33,78,39);
IJ.run(imp, "Measure", "");
#Rename first table!
IJ.renameResults("Results_1");
imp.setRoi(75,49,82,54);
IJ.run(imp, "Measure", "");
#Rename second table!
IJ.renameResults("Results_2");
#Get reference to first table!
win=WindowManager.getWindow("Results_1");
table_1=win.getResultsTable();
table_1.save("C:/YourFolder/results_1.xls");
#Get reference to second table!
win2=WindowManager.getWindow("Results_2");
table_2=win2.getResultsTable();
table_2.save("C:/YourFolder/results_2.xls");

#3

Thank you @Bio7 for the reply, but I am not sure how to apply what you showed me ot my problem.

In fact, what I am doing is looping through each frame of my stack, while performing the particle analysis in one channel (cyan) and using the calculated rois to measure mean intensity in the other channels for the same frame (cherry and venus). After having completed one frame, I reset the roi manager and start again. While loopiing through the rois, I extract the corresponding info from the table to write it in another file. I do this because I would like to be independent of the ResultTable and because I will have to do this thing for several stacks, not only one…
I hope I have explained better the problem :slight_smile:


#4

Why do you have to do it in such a complicated way? Isn’t that a use case where the Redirect to option in Analyze > Set Measurements… can be used (i.e. analyze particles in one channel, get the measurements from the other channel)? You don’t have to export ROIs to the manager to achieve this.


#5

Hi @imagejan, thank you for the advice, I will try to figure out how to use this option in Jython.
I am doing it in a complicated way because I am a student and it is the first time I am facing this problem, so I keep on fixing it by trials and errors… :sweat_smile: