Commit 529ece5a authored by rhaase's avatar rhaase

initial version

parents
This diff is collapsed.
// clij_macro_segmentation.ijm
// ---------------------------
//
// This macro demonstates a workflow consisting of
// * denoising with Gaussian blur
// * background subtraction using the top-hat filter
// * segmentation using thresholding
// * connected components analysis
//
// Goal is counting nuclei in a 3D dataset showing half a
// Tribolium embryo imaged in light sheet microscopy
//
// Author: Robert Haase, rhaase@mpi-cbg.de
// September 2019
// -------------------------------------------------------
run("Close All");
// open dataset
open("C:/structure/teaching/clij_mtz_2020/Nantes_000500.tif");
run("32-bit");
getDimensions(width, height, channels, slices, frames);
time = getTime();
// init GPU
run("CLIJ Macro Extensions", "cl_device=");
Ext.CLIJ_clear();
// send input image to the GPU
input = "input";
rename(input);
Ext.CLIJ_push(input);
// crop out a region to spare time by not processing black pixels
cropped = "cropped";
Ext.CLIJ_crop3D(input, cropped, 128, 110, 0, 719, 714, slices - 1);
// denoising
denoised = "denoised";
Ext.CLIJ_blur3D(cropped, denoised, 2, 2, 0);
// top-hat filter to make all nuclei similarily bright and remove background
background = "background";
temp = "temp";
Ext.CLIJ_minimum3DBox(denoised, temp, 15, 15, 0);
Ext.CLIJ_maximum3DBox(temp, background, 15, 15, 0);
background_subtracted = "background_subtracted";
Ext.CLIJ_subtractImages(denoised, background, background_subtracted);
// thresholding to segment nuclei
thresholded = "thresholded";
// TODO: Apply RenyiEntropy thresholding on GPU
// connected components analysis to differentiate nuclei from each other
label_map = "label_map";
// TODO: Run connected components analysis on GPU
// read out number of objects
Ext.CLIJ_maximumOfAllPixels(label_map);
number_of_objects = getResult("Max", nResults() - 1);
run("Clear Results");
// TODO: Derive statistics of labelled objects
// maximum projection for visualisation
maximum_projected = "maximum_projected";
// TODO: Apply a maximum projection on the GPU
// pull the resulting image from the GPU and show it
Ext.CLIJ_pull(maximum_projected);
run("glasbey on dark");
// measure time and output results
duration = getTime() - time;
print("Number of nuclei: " + number_of_objects);
print("Duration: " + duration + " ms");
// clij_macro_segmentation.ijm
// ---------------------------
//
// This macro demonstates a workflow consisting of
// * denoising with Gaussian blur
// * background subtraction using the top-hat filter
// * segmentation using thresholding
// * connected components analysis
//
// Goal is counting nuclei in a 3D dataset showing half a
// Tribolium embryo imaged in light sheet microscopy
//
// Author: Robert Haase, rhaase@mpi-cbg.de
// September 2019
// -------------------------------------------------------
run("Close All");
// open dataset
open("C:/structure/teaching/clij_mtz_2020/Nantes_000500.tif");
run("32-bit");
getDimensions(width, height, channels, slices, frames);
time = getTime();
// init GPU
run("CLIJ Macro Extensions", "cl_device=");
Ext.CLIJ_clear();
// send input image to the GPU
input = "input";
rename(input);
Ext.CLIJ_push(input);
// crop out a region to spare time by not processing black pixels
cropped = "cropped";
Ext.CLIJ_crop3D(input, cropped, 128, 110, 0, 719, 714, slices - 1);
// denoising
denoised = "denoised";
Ext.CLIJ_blur3D(cropped, denoised, 2, 2, 0);
// top-hat filter to make all nuclei similarily bright and remove background
background = "background";
temp = "temp";
Ext.CLIJ_minimum3DBox(denoised, temp, 15, 15, 0);
Ext.CLIJ_maximum3DBox(temp, background, 15, 15, 0);
background_subtracted = "background_subtracted";
Ext.CLIJ_subtractImages(denoised, background, background_subtracted);
// thresholding to segment nuclei
thresholded = "thresholded";
Ext.CLIJ_automaticThreshold(background_subtracted, thresholded, "RenyiEntropy");
// connected components analysis to differentiate nuclei from each other
label_map = "label_map";
Ext.CLIJx_connectedComponentsLabeling(thresholded, label_map);
// read out number of objects
Ext.CLIJ_maximumOfAllPixels(label_map);
number_of_objects = getResult("Max", nResults() - 1);
run("Clear Results");
Ext.CLIJx_statisticsOfLabelledPixels(cropped, label_map);
// maximum projection for visualisation
maximum_projected = "maximum_projected";
Ext.CLIJ_maximumZProjection(label_map, maximum_projected);
// pull the resulting image from the GPU and show it
Ext.CLIJ_pull(maximum_projected);
run("glasbey on dark");
// measure time and output results
duration = getTime() - time;
print("Number of nuclei: " + number_of_objects);
print("Duration: " + duration + " ms");
// ij_macro_segmentation.ijm
// -------------------------
//
// This macro demonstates a workflow consisting of
// * denoising with Gaussian blur
// * background subtraction using the top-hat filter
// * segmentation using thresholding
// * connected components analysis
//
// Goal is counting nuclei in a 3D dataset showing half a
// Tribolium embryo imaged in light sheet microscopy
//
// Author: Robert Haase, rhaase@mpi-cbg.de
// September 2019
// -------------------------------------------------------
run("Close All");
// open dataset
open("C:/structure/teaching/clij_mtz_2020/Nantes_000500.tif");
time = getTime();
// crop out a region to spare time by not processing black pixels
makeRectangle(128, 110, 719, 714);
denoised = "denoised";
run("Duplicate...", "title=" + denoised + " duplicate");
// denoising
run("Gaussian Blur...", "sigma=2 stack");
// top-hat filter to make all nuclei similarily bright and remove background
background = "background";
run("Duplicate...", "title=" + background + " duplicate");
//run("Minimum 3D...", "x=15 y=15 z=2");
//run("Maximum 3D...", "x=15 y=15 z=2");
run("Minimum...", "radius=15 stack");
run("Maximum...", "radius=15 stack");
imageCalculator("Subtract create 32-bit stack", denoised, background);
// thresholding to segment nuclei
selectWindow("Result of " + denoised);
setAutoThreshold("RenyiEntropy dark stack");
setOption("BlackBackground", true);
run("Convert to Mask", "method=RenyiEntropy background=Dark black");
// connected components analysis to differentiate nuclei from each other
run("3D OC Options", "volume surface nb_of_obj._voxels nb_of_surf._voxels integrated_density mean_gray_value std_dev_gray_value median_gray_value minimum_gray_value maximum_gray_value centroid mean_distance_to_surface std_dev_distance_to_surface median_distance_to_surface centre_of_mass bounding_box dots_size=5 font_size=10 store_results_within_a_table_named_after_the_image_(macro_friendly) redirect_to=none");
run("3D Objects Counter", "threshold=128 slice=48 min.=0 max.=101711872 objects");
// maximum projection for visualisation
run("Z Project...", "projection=[Max Intensity]");
run("glasbey on dark");
// read out number of objects
getStatistics(area, mean, min, max, std, histogram);
number_of_objects = max;
// measure time and output results
duration = getTime() - time;
print("Number of nuclei: " + number_of_objects);
print("Duration: " + duration + " ms");
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