Import ROI in macro with BIOFORMAT

Hello
I have the next Macro :

path = getDirectory(“Choose a Directory”);
list = getFileList(path);
length = list.length;

File.makeDirectory(path + “Folder/”);

//Calculation

for (i=0; i<length; i++) {

n=i+1;
open(path+list[i]);
img = File.nameWithoutExtension();
selectWindow(img+".lsm");

selectWindow(“z stack.lsm”);
run(“StackReg”, “transformation=Translation”);
run(“Subtract Background…”, “rolling=300 stack”);
run(“Split Channels”);
selectWindow(“C1-z stack.lsm”);
run(“Z Project…”, “projection=[Sum Slices]”);
selectWindow(“C3-z stack.lsm”);
run(“Z Project…”, “projection=[Sum Slices]”);
selectWindow(“SUM_C1-z stack.lsm”);
run(“Median…”, “radius=1.2”);
run(“Threshold…”);
setAutoThreshold(“Default dark”);
waitForUser(“Apply Threshold y click OK”);
selectWindow(“SUM_C3-z stack.lsm”);
run(“Median…”, “radius=1.2”);
run(“Threshold…”);
setAutoThreshold(“Default dark”);
waitForUser(“Apply Threshold y click OK”);
imageCalculator(“Divide create 32-bit”, “SUM_C3-z stack.lsm”,“SUM_C1-z stack.lsm”);
selectWindow(“Result of SUM_C3-z stack.lsm”);
saveAs (“Tiff”, path + “Folder/stackratio”);
waitForUser;
//run(“Brightness/Contrast…”);
run(“metamorph”);
run(“Calibration Bar…”);
saveAs (“Tiff”, path + “Folder/map”);
run(“Close All”);
}

I would like to call the bioformat importer and then to import a ROI from the LSM file to measure the fluorescence intensity. Since I am doing this with several files from a folder, I would like to know if there is a way to do the analysis file by file with the macro.

Thank you for any help.

Regards
Pablo

Hi Pablo,

To run the Bio-Formats importer and import ROI’s from your macro you can use the below command, substituting in the image details:

run("Bio-Formats Importer", "open=[/Path/to/image.lsm] autoscale color_mode=Default display_ome-xml display_rois rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");

If you wish to change some of the options the easiest way to probably to record a macro and go through the importer dialog selecting the options you want.

2 Likes

Thank you very much! I will follow your instruction.

Hi
I try your suggestion but it did not work. I could not use bioformat to open the roi manager in my macro. I made a short version to test it but it does not work, please see below:
path = getDirectory(“Choose a Directory”);
list = getFileList(path);
length = list.length;

File.makeDirectory(path + “ImagingAP2/”);

//Calculation

for (i=0; i<length; i++) {

n=i+1;
open(path+list[i]);
img = File.nameWithoutExtension();
selectWindow(img+".lsm");
run("StackReg", "transformation=Translation");
 //setTool("rectangle");
waitForUser("add ROI, Draw ROI, then hit OK");    
  if (selectionType==-1)
     exit("This macro requires an area selection");
  for (k=1; k<=nSlices; k++) 
      setSlice(k);
      getStatistics(area, mean);
      run("Select None");
      run("Subtract...", "value="+mean);
      run("Restore Selection");

run(“Bio-Formats Importer”, “open=[/Path/to/image.lsm] autoscale color_mode=Default display_ome-xml display_rois rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT”);
run(“Close All”);
}

The problem seems to be the "open=[/Path/to/image.lsm]
I do not know how to fix it, I have been trying and read it about it but I cannot find a solution.
Any help I will really appreciated.
Thank you
Pablo

This is the error that i got
Name * Value
Memory * 154MB of 20000MB (<1%)
nImages() * 1
getTitle() * “1.lsm”
path * “C:\Users\Pablo\Desktop\test”
list * array[2]
length * 2
i * 0
n * 1
img * “1”
k * 5
area * 54.2581
mean * 27.1707


Error: The specified file (/Path/to/image.lsm) does not exist. in line 26:
run ( “Bio-Formats Importer” , "open=[/Path/to/image.lsm] autoscale color_mode=Default display_ome-xml display_rois roi…

Hi Pablo
You just need to replace the open(path+list[i]); call in your original macro
i.e.

path=getDirectory("Choose a Directory");
list = getFileList(path);
length = list.length;

for (i=0; i<length; i++) {
   n=i+1;
   image_path=path+list[i];
   run("Bio-Formats Importer", "open=["+image_path+"] autoscale color_mode=Default display_ome-xml display_rois rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
   run("Median...", "radius=1.2");
   run("Threshold...");
   setAutoThreshold("Default dark");
   // continue with the rest of the macro
}

The image will open using Bio-Formats and if the image has a ROI it will be displayed in the ROI manager

Jean-marie

1 Like

Thank you very much, Jean-Marie.
I am going to follow your suggestion.
Thanks