Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lecture_applied_bioimage_analysis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rhaase
lecture_applied_bioimage_analysis
Commits
a759e896
Commit
a759e896
authored
5 years ago
by
rhaase
Browse files
Options
Downloads
Patches
Plain Diff
solution of exercise 06
parent
d86eeb8f
Branches
master
No related tags found
1 merge request
!4
Alternate tools
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
06_example_code/visualise_area_and_shape_in_colors.ijm
+107
-0
107 additions, 0 deletions
06_example_code/visualise_area_and_shape_in_colors.ijm
06_example_code/visualise_area_and_shape_in_colors_ui.ijm
+107
-0
107 additions, 0 deletions
06_example_code/visualise_area_and_shape_in_colors_ui.ijm
with
214 additions
and
0 deletions
06_example_code/visualise_area_and_shape_in_colors.ijm
0 → 100644
+
107
−
0
View file @
a759e896
//@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
This diff is collapsed.
Click to expand it.
06_example_code/visualise_area_and_shape_in_colors_ui.ijm
0 → 100644
+
107
−
0
View file @
a759e896
// @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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment