Analyze particles of particle-free images

Dear all,

I sincerely hope you can help me with my issues (my first time using Fiji…) Thank you very much!

What I am trying to do:

I am hoping to quantify the % area in an image that is +ve for antibody, involving 4 different antibodies (1, 2, 3, 4). Only one antibody is used to stain each image. My workflow is as follow:

  1. Obtain Brightfield images from slide scanner

  2. Segment an image into +ve and -ve for antibody of interest using Trainable Weka Segmentation. I saved and applied the classifier to all the Brightfield images of the antibody of interest.

  3. Convert the images into 8-bit greyscale.

  4. Run the following macro that a colleague has kindly created for me (below). The macro gives me the summary table with a column that gives me the % of area +vely stained for each image

    print("\\Clear");
    roiManager("reset");
    setBatchMode(true);
    var finalName="default";
    var binaryID;
    
    
    //Input and ouput directory
    dir1=getDirectory("Select input folder ...");  		//select the directory where your files are
    dir2=getDirectory("Save result in folder ..."); 	//select the directory where to save your results, always better to have a different folder from the input folder
    list=getFileList(dir1);								//list all the files in the input folder
    for (i=0; i<list.length; i++){						//loop though all the files
    		inputPath=dir1+list[i];
    		open(inputPath);
    		title=getTitle();
    		finalName= substring(title, 0, indexOf(title,"."));
    		binarySavePath=dir2+finalName+"_binary";
    		run("Make Binary");
    		run("Properties...", "channels=1 slices=1 frames=1 unit=um pixel_width=0.220 pixel_height=0.220 voxel_depth=1");
    		saveAs("tif", binarySavePath);
    		binaryID=getImageID();
    		selectImage(binaryID);
    		run("Analyze Particles...", "size=0-infinity pixel summarize add");   //change range for cell size filtering
    		selectImage(binaryID);
    		roiManager("save", dir2+finalName+"_roiSet.zip");
    		roiManager("reset");
    }
    selectWindow("Summary");
    resultsPath=dir2+"_results";
    saveAs("text", resultsPath);
    

The problem:

So this workflow has worked perfectly fine with antibody 1 and 2 and 3. However, when it comes to antibody 4, I am expecting some of the images to not be stained at all i.e. no +ve areas in these images. Everything works fine until the part where I am trying to run the macro - the macro/loop keeps on getting interrupted because ‘the selection list is empty’ i.e. no particles were analysed.

I was therefore wondering if someone can advise me on how to let the macro/loop continue despite the absence of particles in the images? I am fine with the summary table showing 0 for the particle-free images, but the analysis was continuously interrupted and I am not sure how I can resolve this?

Please help this desperate student out…

Many thanks and best wishes,
Edward

Hi @etaetaa

So… I am not sure exactly if this will solve your issue - but I think what you need is an if/else statement to avoid those interruptions.

Perhaps something like this:

list=getFileList(dir1);  //list all the files in the input folder
if (list.length == 0) {
      // EITHER:
      // DO NOTHING - just leave this space between {} empty, nothing will be done
      // OR...
      // DO SOMETHING ... perhaps print out a message saying list is empty?! whatever you find most helpful.
} else {
for (i=0; i<list.length; i++){  //loop though all the files
		inputPath=dir1+list[i];
		open(inputPath);
		title=getTitle();
		finalName= substring(title, 0, indexOf(title,"."));
		binarySavePath=dir2+finalName+"_binary";
		run("Make Binary");
		run("Properties...", "channels=1 slices=1 frames=1 unit=um pixel_width=0.220 pixel_height=0.220 voxel_depth=1");
		saveAs("tif", binarySavePath);
		binaryID=getImageID();
		selectImage(binaryID);
		run("Analyze Particles...", "size=0-infinity pixel summarize add");   //change range for cell size filtering
		selectImage(binaryID);
		roiManager("save", dir2+finalName+"_roiSet.zip");
		roiManager("reset");
                }
}

NOTE: you might have to modify this code a bit to get it working as you wish, but it’s a start!

Hope this helps!

eta :slight_smile: