Commit b193b216 authored by rhaase's avatar rhaase

Merge branch 'alternate_tools' into 'master'

Alternate tools

See merge request !4
parents 7df7da5e c6157d61
//@File(style="directory") folder
//@int maximum_aspect_ratio
//@int minimum_cell_size
//@int maximum_cell_size
//
// This script analyses a time lapse of images showing yeast cells.
// It counts the number of round cells over time and visualises
// cells in different colors depending on their features:
// * red: too small or too large
// * yellow: round (dying)
// * green: elongated (alive)
//
// Robert Haase, rhaase@mpi-cbg.de
// May 2019
//
// configuration
//folder = "C:/structure/teaching/lecture_applied_bioimage_analysis/05_example_code_and_data/rounding_assay/";
result_file = "result_shape_count.csv";
// how are round cells identified?
//maximum_aspect_ratio = 2;
// size constraints for yeast-cells
//minimum_cell_size = 10; // in pixels
//maximum_cell_size = 200; // in pixels
// prepare resulting CSV file
if ( File.exists(folder + result_file) ) {
File.delete(folder + result_file);
}
File.append("File, Number of round cells, Number of elongated cells", folder + result_file);
// access the folder
filelist = getFileList(folder);
for (i = 0; i < lengthOf(filelist); i++) {
//for (i = 30; i < 31; i++) {
filename = folder + filelist[i];
if (endsWith(filename, ".tif")) {
// open an image from the rounding assay
open(filename);
// save the window title for later - we want to switch to this image
original_image_title = getTitle();
// duplicate the image and segment it
run("Duplicate...", " ");
setAutoThreshold("Triangle dark");
run("Convert to Mask");
// binary closing
run("Dilate");
run("Dilate");
run("Erode");
run("Erode");
// connected components analysis -> send results to ROI Manager
run("Analyze Particles...", " show=Nothing add");
// switch back to original image
selectWindow(original_image_title);
roiManager("Show None");
number_of_round_regions = 0;
number_of_elongated_regions = 0;
number_of_regions = roiManager("count");
for (j = 0; j < number_of_regions; j++ ) {
// measure area ( = pixel count) and shape
run("Set Measurements...", "area shape redirect=None decimal=3");
roiManager("Select", j);
roiManager("Measure");
pixel_count = getResult("Area", nResults - 1);
aspect_ratio = getResult("AR", nResults - 1);
// visualise if ROIs are too small or not
if (pixel_count > minimum_cell_size && pixel_count < maximum_cell_size) {
if (aspect_ratio > maximum_aspect_ratio) {
number_of_elongated_regions ++;
Overlay.addSelection("green");
} else {
number_of_round_regions ++;
Overlay.addSelection("yellow");
}
} else {
Overlay.addSelection("red");
}
}
File.append(filename + "," + number_of_round_regions + ", " + number_of_elongated_regions , folder + result_file);
// clean up after the job is done
if (number_of_regions > 0) {
roiManager("deselect");
roiManager("delete");
}
run("Clear Results");
run("Flatten");
save(filename + "_result_visualisation.jpg");
run("Close All");
}
}
\ No newline at end of file
// @File(style="directory") folder
// @int(value=2, persistent=False) maximum_aspect_ratio
// @int(value=10, persistent=False) minimum_cell_size
// @int(value=200, persistent=False) maximum_cell_size
//
// This script analyses a time lapse of images showing yeast cells.
// It counts the number of round cells over time and visualises
// cells in different colors depending on their features:
// * red: too small or too large
// * yellow: round (dying)
// * green: elongated (alive)
//
// Robert Haase, rhaase@mpi-cbg.de
// May 2019
//
// configuration
//folder = "C:/structure/teaching/lecture_applied_bioimage_analysis/05_example_code_and_data/rounding_assay/";
result_file = "result_shape_count.csv";
// how are round cells identified?
//maximum_aspect_ratio = 2;
// size constraints for yeast-cells
//minimum_cell_size = 10; // in pixels
//maximum_cell_size = 200; // in pixels
// prepare resulting CSV file
if ( File.exists(folder + result_file) ) {
File.delete(folder + result_file);
}
File.append("File, Number of round cells, Number of elongated cells", folder + result_file);
// access the folder
filelist = getFileList(folder);
for (i = 0; i < lengthOf(filelist); i++) {
//for (i = 30; i < 31; i++) {
filename = folder + filelist[i];
if (endsWith(filename, ".tif")) {
// open an image from the rounding assay
open(filename);
// save the window title for later - we want to switch to this image
original_image_title = getTitle();
// duplicate the image and segment it
run("Duplicate...", " ");
setAutoThreshold("Triangle dark");
run("Convert to Mask");
// binary closing
run("Dilate");
run("Dilate");
run("Erode");
run("Erode");
// connected components analysis -> send results to ROI Manager
run("Analyze Particles...", " show=Nothing add");
// switch back to original image
selectWindow(original_image_title);
roiManager("Show None");
number_of_round_regions = 0;
number_of_elongated_regions = 0;
number_of_regions = roiManager("count");
for (j = 0; j < number_of_regions; j++ ) {
// measure area ( = pixel count) and shape
run("Set Measurements...", "area shape redirect=None decimal=3");
roiManager("Select", j);
roiManager("Measure");
pixel_count = getResult("Area", nResults - 1);
aspect_ratio = getResult("AR", nResults - 1);
// visualise if ROIs are too small or not
if (pixel_count > minimum_cell_size && pixel_count < maximum_cell_size) {
if (aspect_ratio > maximum_aspect_ratio) {
number_of_elongated_regions ++;
Overlay.addSelection("green");
} else {
number_of_round_regions ++;
Overlay.addSelection("yellow");
}
} else {
Overlay.addSelection("red");
}
}
File.append(filename + "," + number_of_round_regions + ", " + number_of_elongated_regions , folder + result_file);
// clean up after the job is done
if (number_of_regions > 0) {
roiManager("deselect");
roiManager("delete");
}
run("Clear Results");
run("Flatten");
save(filename + "_result_visualisation.jpg");
run("Close All");
}
}
\ No newline at end of file
// Random image generator
//
// This script expects two target folders and will generate two different kinds of
// random images according to its configuration.
//
// Author: Robert Haase, rhaase@mpi-cbg.de
// May 2019
//
////////////////////////////////////////////////////////
target_folder_A = "C:/structure/teaching/lecture_applied_bioimage_analysis/07_examples/example_images/condition_A/"
target_folder_B = "C:/structure/teaching/lecture_applied_bioimage_analysis/07_examples/example_images/condition_B/"
// how many images and how many objects per image?
number_of_images = 10;
number_of_cells_per_image = 25;
number_of_cells_standard_variation = 5;
// configure intensity and size of the random blobs
condition_A_intensity = 0.5;
condition_B_intensity = 0.75;
condition_A_blob_radius = 5;
condition_B_blob_radius = 10;
// main loop for number of images
function main() {
for (i = 0; i < number_of_images; i++ ) {
makeAndSaveImage(target_folder_A + "ImageA" + i + ".tif", condition_A_intensity, condition_A_blob_radius);
makeAndSaveImage(target_folder_B + "ImageB" + i + ".tif", condition_B_intensity, condition_B_blob_radius);
}
}
// makes an image with random blobs in given intensity and radius
function makeAndSaveImage(filename, intensity, radius) {
newImage("Image", "8-bit black", 512, 512, 1);
seedRandomBlobs(intensity, radius);
save(filename);
close();
}
// makes random blurry and noisy blobs
function seedRandomBlobs(intensity, radius) {
getDimensions(width, height, channels, slices, frames);
number_of_objects = number_of_cells_per_image + random("gaussian") * number_of_cells_standard_variation;
for (i = 0; i < number_of_objects; i++) {
x = random() * width;
y = random() * height;
// make a wobbly blob
for (j = 0; j < 5; j++) {
r = max(1, radius + (random("gaussian")-0.5) * radius);
makeOval(x + random() * r / 2 - r, y + random() * r / 2 - r, r * 2, r * 2);
run("Add...", "value=255");
}
}
run("Select None");
run("Multiply...", "value=" + intensity);
// blur the edges of the blobs and make the image noisy
run("Gaussian Blur...", "sigma=" + radius);
run("Add Specified Noise...", "standard=25");
}
function max(a, b) {
if (a > b) {
return a;
} else {
return b;
}
}
main();
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment