Assignment title: Information
Need to develop a plugin that is able to separate each image of droplets and input just that images data into an excel spread sheet. Not the total sum of all images.
Not sure if each file should roll over to new directory?? Need to try to separate output data?
Here is all the code, some are online macros that are used, But still not getting it to run . Getting error messages? I think due to directory issues?
I am not sure where the error is really occurring, that is why I am not able to fix it.
// See http://rsb.info.nih.gov/ij/macros
//Global variables
var inputDir;
var outputDirectory;
var imageScalePixelsPerUm=10;
var annotationHeight=186;
// Get Directories
inputDir = getDirectory("Input directory");
outputDir = getDirectory("Output directory");
Dialog.create("Measure Particles");
Dialog.addNumber("Image Scale (pixels/um): ", imageScalePixelsPerUm, 0, 5, "");
Dialog.addNumber("Annotation Height: ", annotationHeight, 0, 3, "px");
Dialog.show();
// Get Remaining Properties
imageScalePixelsPerUm=Dialog.getNumber();
annotationHeight=Dialog.getNumber();
processFolder(inputDir);
// Retrieves file names of input directory and calls processFile to generate statistics.
function processFolder(inputDir) {
list = getFileList(inputDir);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(list[i]))
processFolder("" + input + list[i]);
else
processFile(inputDir, outputDir, list[i]);
}
}
// Process the individual file
function processFile(input, output, file) {
print("Processing: " + input + file);
path = input + file;
open(path);
name = getTitle();
extPosition = indexOf(name, ".");
partialName = substring(name, 0, extPosition);
newTitle = substring(name, 0, extPosition)+".Cropped.tif";
imageWidth = getWidth();
imageHeight = getHeight();
// Should convert use of global annotationHeight variable to function parameter.
imageCroppedHeight = imageHeight - annotationHeight;
//setTool("rectangle");
makeRectangle(0, 0, imageWidth, imageCroppedHeight);
run("Copy");
newImage(newTitle, "8-bit black", imageWidth, imageCroppedHeight, 1);
run("Paste");
// Close original source image file (unchanged).
selectWindow(file);
run("Close");
// Select new cropped file.
selectWindow(newTitle);
// Subtract the background
run("Subtract Background...", "rolling=50");
// Perform initial segmentation with SRM.
run("Statistical Region Merging", "q=25 showaverages");
// srmTitle = getTitle();
// print ("Active Window Title (srm?): "+srmTitle);
// Close the new cropped file.
selectWindow(newTitle);
run("Close");
// Apply Threshold
setAutoThreshold("Li dark");
// Mean threshold sometimes produces better results.
//setAutoThreshold("Mean dark");
setOption("BlackBackground", true);
run("Convert to Mask");
// Get the title of the new file.
// print ("Active Window Title Post Threshold: "+getTitle());
// Remove any noise
run("Despeckle");
// Make Binary
run("Make Binary");
// Run BoneJ
run("Thickness", "thickness graphic mask");
// Convert image to 8-bit grayscale
run("8-bit");
// Threshold with default
setAutoThreshold("Default dark");
run("Convert to Mask");
// Make Binary
run("Make Binary");
// Watershed the image to separate particles
run("Watershed");
// Specify the types of measurements desired.
run("Set Measurements...", "area centroid center perimeter bounding shape feret's integrated redirect=None decimal=3");
// Convert global variable usage to new parameter of function.
// Set scale
run("Set Scale...", "distance=1 known="+imageScalePixelsPerUm+" pixel=1 unit=um global");
// Analyze image for particles.
run("Analyze Particles...", "pixel circularity=0.25-1.00 show=Outlines display exclude clear add");
// Save Results
selectWindow("Results");
saveAs("Results", output+partialName+".csv");
run("Close");
// Save outline image file
newOutputFileName = partialName+'.Outline.tif';
// Prefer a better way to ensure that new image file is selected.
saveAs(getTitle(), output+newOutputFileName);
// Close all image windows
run("Close All");
if (isOpen("ROI Manager")) {
selectWindow("ROI Manager");
run("Close");
}
}
Next:
// See http://rsb.info.nih.gov/ij/macros
//Author: Jophin John
//Global variables
var inputDir;
var outputDirectory;
var imageScalePixelsPerUm=10;
var annotationHeight=186;
// Get Directories
inputDir = getDirectory("Input directory");
outputDir = getDirectory("Output directory");
Dialog.create("Measure Particles");
Dialog.addNumber("Image Scale (pixels/um): ", imageScalePixelsPerUm, 0, 5, "");
Dialog.addNumber("Annotation Height: ", annotationHeight, 0, 3, "px");
Dialog.show();
//Get Remaining Properties
imageScalePixelsPerUm=Dialog.getNumber();
annotationHeight=Dialog.getNumber();
processFolder(inputDir);
// Retrieves file names of input directory and calls processFile to generate statistics.
function processFolder(inputDir) {
list = getFileList(inputDir);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(list[i]))
processFolder("" + input + list[i]);
else
processFile(inputDir, outputDir, list[i]);
}
}
// Process the individual file
function processFile(input, output, file) {
print("Processing: " + input + file);
path = input + file;
open(path);
name = getTitle();
extPosition = indexOf(name, ".");
partialName = substring(name, 0, extPosition);
newTitle = substring(name, 0, extPosition)+".Cropped.tif";
imageWidth = getWidth();
imageHeight = getHeight();
//intial processing of the file by reducing noise
run("Despeckle");
//Run initial threshold prior to cropping (produced better results than post crop thresholding)
//presumably cropping does reduce pixels or change the scale and creates more noise
run("Threshold","Li dark");
// Should convert use of global annotation - Height variable to function parameter.
imageCroppedHeight = imageHeight - annotationHeight;
makeRectangle(0, 0, imageWidth, imageCroppedHeight);
run("Copy");
newImage(newTitle,"8-bit" ,imageWidth, imageCroppedHeight,1);
run("Paste");
// Close original source image file (unchanged).
selectWindow(file);
run("Close");
// Select new cropped file.
selectWindow(newTitle);
//Took 69-76 from http://imagej.net/macros/CellSegmentation.txt
//This produced best results for blurring images and contouring droplets
run("8-bit");
run("Gaussian Blur...", "sigma=20");
setAutoThreshold();
run("Convert to Mask");
setThreshold(255, 255);
run("Tile");
// Highlighting droplets from fiber via BoneJ Thickness function (Density based differentiation
run("Thickness", "thickness graphic mask");
//Thickness produces 32 bit images which needs to be converted to threshold to seperate
//droplets and fiber
run("8-bit");
run("Threshold","Li dark");
// Run binary and 8-bit to see results of thresholding
run("8-bit");
run("Make Binary");
//Repeat 77-90 for reducing fiber from droplets (needs to be iterated in a for loop
run("8-bit");
run("Sharpen");
//run("Gaussian Blur...", "sigma=1.5");
run("Convert to Mask");
run("Thickness", "thickness graphic mask");
run("8-bit");
run("Threshold","RenyiEntropy dark");
run("8-bit");
run("Make Binary");
//Deleted Watershedding from previous work as it seems to fractionate droplets.
//This gives a better result from previous groups work.
// Droplets are counted and measured with way less errors and accurate thresholding
// Specify the types of measurements desired.
run("Set Measurements...", "area centroid center perimeter bounding shape feret's integrated redirect=None decimal=3");
// Convert global variable usage to new parameter of function.
// Set scale
run("Set Scale...", "distance=1 known="+imageScalePixelsPerUm+" pixel=1 unit=um global");
// Analyze image for particles.
run("Analyze Particles...", "pixel circularity=0.25-1.00 show=Outlines display exclude clear add");
// Save Results
selectWindow("Results");
saveAs("Results", output+partialName+".csv");
run("Close");
// Save outline image file
newOutputFileName = partialName+'.Outline.tif';
// Prefer a better way to ensure that new image file is selected.
saveAs(getTitle(), output+newOutputFileName);
// Close all image windows
run("Close All");
if (isOpen("ROI Manager")) {
selectWindow("ROI Manager");
run("Close");
}
}
Images particles that need to be individual data and not the total sum:
Attached image files SEMS to docs