Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
// 2022-04-08 by Lion Raaz (raaz@molgen.mpg.de)
// in collaboration with Sophia Mähr
// This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
// (CC BY-SA 4.0) https://creativecommons.org/licenses/by-sa/4.0/
// available under https://github.molgen.mpg.de/raaz/measure_nuclei
// script to measure nuclei roundness (Round) and output as (short d)/(long d) = values (0;1] in a csv
// Table output corresponds to measurement function output:
// ID,Area,Mean,Min,Max,Circ.,AR,Round,Solidity,Filename
// PREPARATION
// make sure no special characters are in the file names (e.g. parentheses "()" etc.)
showMessageWithCancel("Hi there!","This is the nuclei roundness measurement script. \n Please make sure filenames do not contain special charaters such as ()*&^%$#@! \n Letters, numbers, dots, underscores, dashes and spaces work. \n Have Fun!");
run("Clear Results"); // clear the results table of any previous measurements
// prevent ImageJ from showing the processing steps during
// processing of a large number of images, speeding up the macro
setBatchMode(true);
// Show the user a dialog to select a directory of images
inputDirectory = getDirectory("Choose a Directory of Images");
// Get the list of files from that directory
fileList = getFileList(inputDirectory);
// Show user dialog to select channel for analysis
Dialog.create("A tännschn please");
output_file = "results.csv";
//width=512; height=512;
channels = newArray("C1", "C2", "C3", "C4", "C5");
binMethod = newArray("Default", "Huang", "Li");
autoAdjust = false;
Dialog.create("A tännschn please");
Dialog.addMessage("Please rename the output file if desired and select which channel is to be analysed.");
Dialog.addString("Output file:", output_file, 30);
Dialog.addChoice("Channel:", channels, "C3");
Dialog.addChoice("Method for Binary conversion:", binMethod, "Default");
//Dialog.addNumber("Width:", width);
//Dialog.addNumber("Height:", height);
Dialog.addCheckbox("Auto adjust brightness", true);
Dialog.show();
output_file = Dialog.getString();
//width = Dialog.getNumber();
//height = Dialog.getNumber();;
channel = Dialog.getChoice();
binMethod = Dialog.getChoice();
autoAdjust = Dialog.getCheckbox();
for (i = 0; i < fileList.length; i++)
{
if (fileIsImage(fileList[i])) {
processImage(fileList[i]);
}
}
// Now disable BatchMode since we are finished
setBatchMode(false);
// Update the results table so it shows the filenames
updateResults();
// Show a dialog to allow user to save the results file
//outputFile = File.openDialog("Save results file");
// Save the results data
// selectWindow("Results"); // option seems not to be necessary. still suspicious though
saveAs("results",inputDirectory + output_file);
showMessage("Finish", "The images were analysed. Results are saved under:\n"+ inputDirectory + output_file);
function fileIsImage(imageFile) {
// check if file is .czi
if (endsWith(imageFile, ".czi")){
return(1);
} else {
return(0);
}
}
function processImage(imageFile) {
// analyze channel 3 of image for roundness
// Store the number of results before executing the commands,
// so we can add the filename just to the new results
prevNumResults = nResults;
run("Bio-Formats", "open=[" + inputDirectory + imageFile + "] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
// Get the filename from the title of the image that's open for adding to the results table
// We do this instead of using the imageFile parameter so that the
// directory path is not included on the table
filename = getTitle();
run("Split Channels");
selectWindow(channel + "-" + filename);
if (autoAdjust) {
run("Enhance Contrast", "saturated=0.35");
run("Apply LUT");
}
setOption("BlackBackground", true);
setAutoThreshold(binMethod + " dark");
run("Convert to Mask");
//run("Make Binary", "method=" + binMethod + " background=Default calculate black");
run("Fill Holes");
run("Set Measurements...", "area mean min shape redirect=None decimal=3");
run("Analyze Particles...", "size=40-300 circularity=0.05-1.00 display exclude add");
// Now loop through each of the new results, and add the filename to the "Filename" column
for (row = prevNumResults; row < nResults; row++)
{
setResult("Filename", row, filename);
}
close("*"); // Closes all images
}