Applying macro to open image sequence


#1

Hello all.

I am trying to figure out a way to run the macro “Mitochondrial Morphology” to an image sequence I have open. I tried using the batch process however this requires you to select the folder and then run the macro immediately. I need to have the sequence open prior in order to manually color threshold all sequences as well as designate an ROI. I have tried messing with the macro code but have had no luck.

I have very little experience with imageJ/computers so any help is greatly appreciated.

Thank you.


#2

Hey @RyanL24

So… I am learning these things myself … I might not be understanding your problem completely, but from what I can gather - I would try to adapt and run something like this code below in your Script Editor.

// @File(label = "Input directory", style = "directory") input
// @File(label = "Output directory", style = "directory") output
// @String(label = "File suffix", value = ".tif") suffix

processFolder(input); // calls the function below

// function to scan folders/subfolders/files to find files with correct suffix
// you can change the suffix above according to the type of image file you want to process
function processFolder(input) {
	list = getFileList(input);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + list[i]))
			processFolder("" + input + list[i]); 
		if(endsWith(list[i], suffix))
			yourMacroCode(input, output, list[i]); // calls your macro code below
	}
}

// this function runs your inserted macro code (you can rename the function)
function yourMacroCode(input, output, file) {
        // ADD YOUR MACRO CODE HERE TO DO PRE-PROCESSING
               // including thresholding, ROI designation, etc.
        // INSERT YOUR MACRO CODE HERE TO DO THE MITOCHONDRIAL MORPHOLOGY
	// Leave these print statements until things work, then remove them.
	print("Processing: " + input + file);
	print("Saving to: " + output);
}

Those first lines of code are Script Parameters… you can read more about them here.

I hope this helps get you started a bit in any case. Perhaps a more advanced person can give you a better answer…

eta :slight_smile:


Macro problems: paste results table to excel file; run loop that closes image, opens next image, and repeats macro commands
#3

Thank you so much for the reply. I am trying this code but not having success. Let me try to explain a little better. My goal is to:

-Import an image sequence
-Color Threshold the entire sequence (this I can do manually on one image and then apply to rest of stack)
-Designate an ROI

These three steps I can do manually without any macro

Then I want to run the mitochondrial morphology macro in a way that it analyzes every image in the sequence in one go and spits back the numbers for each image.

Hope that helps. Again thank you so much.


#4

@RyanL24

Would you be able to post an example image to test? One that is thresholded, etc. ? Are your sequences of images over time or z-positions ??

Then we can better assess what is going on …

Too - you can check the built-in macro functions to see if any might help you move slice-by-slice to process each one individually using a for loop or so.

eta


#5

Sequences are images over time. It is from video that I have separated into individual frames.

Here is an individual image


#6

ok - this is rough and not tested… (the image you posted was just a screen-shot - correct? i would need the original dataset to really try it…)

Something like:

getDimensions(width, height, channels, slices, frames)
i = 1;
while (i <= frames) {
	Stack.setFrame(i);
	// insert your code here to do the thing you want per frame
	i++;
}

not sure if this is the best way to do this… but it’s a start for you i hope!

eta


#7

Yes it was just a screen shot. Here is a sample set.

The code I am using for the mitochondria macro is as followed:

{
	run("Set Measurements...", "area circularity fit perimeter redirect=None decimal=3");
	run("Analyze Particles...", "display results summarize size distribution minimum=30 maximum=100000000 bins=100   pixel show=Outlines  display summarize");
	for (i=0; i<nResults; i++){MA += getResult('Area', i);MP += getResult('Perim.', i);MC += getResult('Circ.', i);LA += getResult('Minor', i);             
}
Mi=LA/i;
AMA=MA/i;   
AMP=MP/i;
AMC=MC/i;
Rmorph=AMA/AMP;
Rmorph2=Rmorph/Mi;
Rmorph3=Rmorph/AMC
 run("Restore Selection");
setAutoThreshold();
 //run("Threshold...");
run("Fill", "slice");
run("Measure"); // Select the outline of the cell containing mitos on the appropriate channel only

TA=getResult('Area');
R=(MA/TA)*100; // Measures the % of the area occupied by mitochondria in the cytoplasm

print(getTitle());  print("Count:"+i); print ("Total Area Mitos:"+MA); print ("Cellular Area:"+TA); print ("Mito Content:"+R); print ("Perimeter Mitos:"+MP); print ("Circularity mitos:"+MC); print ("Avg. Perimeter:"+AMP); print ("Avg. Area:"+AMA); print ("Avg. Circularity:"+AMC); print ("Area/Perim:"+Rmorph);        
                    print("Area/Perimetr normalized to minor axis.:"+Rmorph2);print("Minor Axis:"+Mi);print("Area/Perimeter normalized to circularity:"+Rmorph3);
          // Prints out the Sum of area of mitos, Cellular area, count and Ratio
           
selectWindow("Results");
selectWindow("Log");
beep();

}

#8

Anyone have any other ideas? Thank you so much


#9

You could try to use the command waitForUser(string). This enables you to set threshold values during the analysis and to create a ROI. Just insert this in your macro in the right place. However, this means that you’ve to specify the ROI and threshold values during the analysis.

If you would like to specify the ROI and threshold values before the analysis, I doubt it if the Macro language can do this for you. I’m certain that a script in Java can do the job.

Hope this will help you out.