ImageJ Plugin Editing Problem

2 posts / 0 new
Last post
smvargas's picture
ImageJ Plugin Editing Problem

Hello all! 

I am new to ImageJ and am having a little trouble figuring out how to edit plugins.  I copied the code from the text file that was saved under ImageJ>Plugins>Analyze> called Batch_Measure.txt.  Batch_Measure.txt contains code that measures a folder of images, and I just modified the run commands in the code to do my own analysis of a folder of images.  The part I am having trouble with is in the run() section of the code.  The run("Set Scale...") and run("Analyze Particles...") commands are not working. 

I keep getting the error message:
Unrecognised command : "Set Scale..."
Unrecognised command : "Analyze Particles..."

I thought I was calling them correctly because I used the Record Macro function of ImageJ to come up with the run() commands I used, but I may be wrong and I am not sure how to debug it.

The run("8-bit") and run("Binary") commands are working, so I am a little confused. (If you block the Set Scale and Analyze Particles using //, and run the setBatchMode by deleting the //, it works and a Binary, 8-Bit image ready for analysis appears)
My goal with this modification is to be able to create a directory of images and automate a macro that I had already written to analyze all of the images at once and record the results.
If I am just going about this in the wrong way or if anyone can help, please let me know!  I have attached what I have been working on here but unfortunately I couldn't figure out how to upload it as an attachment in plain text.

//this is my modified code to analyze a folder of images from a directory I choose

dir = getDirectory("Choose a Directory ");
list = getFileList(dir);
setOption("display labels", true);
for (i=0; i<list.length; i++) {
    path = dir+list[i];
    showProgress(i, list.length);
    if (nImages>=1) {
        run("Set Scale…", "distance=1392 known=91 pixel=1 unit=um");
        run("Make Binary");
        run("Analyze Particles…", "size=6.63-Infinity circularity=0.00-1.00 show=Outlines display");
        // setBatchMode(false);
    } else
        print("Error opening "+path);

smvargas's picture
I'm still not sure exactly

I'm still not sure exactly what was wrong with that code, but a friend helped me reorganize it and it works now!
Here's the working script just in case someone else has a similar problem and would benefit from looking at it.

// ImageJ Script
// Date: Oct, 2013
// Author: smvargas
// Function: Analyzes a directory of images and calculates the area of
// outlined sections in image.

source_dir = getDirectory("Source"); // chooses source directory
dest_dir = getDirectory("Destination"); // chooses output directory to save photos
list = getFileList(source_dir); // creates list of all files in source directory
setBatchMode(true); //batch mode - multiple files
for (i = 0; i < list.length; i++){ // loop through all the files and apply analysis
    showProgress(i+1, list.length);
    open(source_dir+list[i]); // opens image
    run("8-bit"); // make image 8-bit
    run("Set Scale...", "distance=1392 known=91 pixel=1 unit=um"); // scale image: distance= pixel # of image, known= known um measurement, unit=um
    setOption("BlackBackground", false);
    run("Make Binary");  // make image Binary
    run("Analyze Particles...", "size=6.63-Infinity circularity=0.00-1.00 show=Outlines display");  // analyze particles to measure area of outlined object
    saveAs("TIFF", dest_dir+list[i]); // save file in output directory as tif
    close(); // closes image