diff --git a/06_example_code/visualise_area_and_shape_in_colors.ijm b/06_example_code/visualise_area_and_shape_in_colors.ijm new file mode 100644 index 0000000000000000000000000000000000000000..eb2429130a2f720e32353c1e09de3dbf662ecc9e --- /dev/null +++ b/06_example_code/visualise_area_and_shape_in_colors.ijm @@ -0,0 +1,107 @@ +//@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 diff --git a/06_example_code/visualise_area_and_shape_in_colors_ui.ijm b/06_example_code/visualise_area_and_shape_in_colors_ui.ijm new file mode 100644 index 0000000000000000000000000000000000000000..a9771001204fcf0b643e95d2f4d8c35bf6ae2fae --- /dev/null +++ b/06_example_code/visualise_area_and_shape_in_colors_ui.ijm @@ -0,0 +1,107 @@ +// @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