diff --git a/07_examples/cellprofiler/SegmentBlobImage_Exercise.cpproj b/07_examples/cellprofiler/SegmentBlobImage_Exercise.cpproj new file mode 100644 index 0000000000000000000000000000000000000000..4e970ae6a79edd4c54dac2332e0307224ca90636 Binary files /dev/null and b/07_examples/cellprofiler/SegmentBlobImage_Exercise.cpproj differ diff --git a/07_examples/imagej/BlobImagesSegmentation_exercise.ijm b/07_examples/imagej/BlobImagesSegmentation_exercise.ijm new file mode 100644 index 0000000000000000000000000000000000000000..b2161e670a2e73365c4f1f18e7e20c14a5d3187d --- /dev/null +++ b/07_examples/imagej/BlobImagesSegmentation_exercise.ijm @@ -0,0 +1,55 @@ +// blob segmentation of images in folders +// +// This script analyses folders full of image with blobs and measures their average size +// +// Author: Robert Haase, rhaase@mpi-cbg.de +// May 2019 +// +/////////////////////////////////// + +folder = "C:/structure/teaching/lecture_applied_bioimage_analysis/07_examples/example_images/" + +function main() { + run("Clear Results"); + + processFolder(folder + "condition_A/"); + saveAs("Results", folder + "ResultsA.xls"); + run("Clear Results"); + + processFolder(folder + "condition_B/"); + saveAs("Results", folder + "ResultsB.xls"); + run("Clear Results"); +} + +function processFolder(foldername) { + + filelist = getFileList(foldername); + number_of_files_in_folder = lengthOf(filelist); + + // go through all images, segment them and collect results in a table + for (i = 0; i < number_of_files_in_folder; i++) { + open(foldername + filelist[i]); + + processImage(); + + close(); + } +} + +function processImage() { + // remoive noise + run("Gaussian Blur...", "sigma=5"); + + // segment + setAutoThreshold("Huang dark"); + setOption("BlackBackground", true); + run("Convert to Mask"); + + // analyze + run("Set Measurements...", "area redirect=None decimal=3"); + run("Analyze Particles...", "display"); +} + +main() { + +} \ No newline at end of file diff --git a/07_examples/knime/BlobImagesSegmentation_Exercise.knwf b/07_examples/knime/BlobImagesSegmentation_Exercise.knwf new file mode 100644 index 0000000000000000000000000000000000000000..da5d9720bae5018304a803de960e9d9582135846 Binary files /dev/null and b/07_examples/knime/BlobImagesSegmentation_Exercise.knwf differ diff --git a/07_examples/python/BlobsSegmentation_Exercise.py b/07_examples/python/BlobsSegmentation_Exercise.py new file mode 100644 index 0000000000000000000000000000000000000000..e483bee98721f64f242da1569e76f8a7eda74543 --- /dev/null +++ b/07_examples/python/BlobsSegmentation_Exercise.py @@ -0,0 +1,82 @@ +# blobs segmentation +# +# This script processes a folder with images containing blobs. +# It measures the area of all blobs and save them to disc. +# +# Author: Robert Haase, rhaase@mpi-cbg.de +# May 2019 +# +#################################33 + +import os +from tifffile import imread +from skimage import filters +from skimage import measure +import pandas as pd + +# set which directory should be processed +directory = 'C:/structure/teaching/lecture_applied_bioimage_analysis/07_examples/example_images/' + +blur_sigma = 5 + +# setup an empty table +table = [[], [], [], [], []] + +def main(): + processFolder(directory + "condition_A/"); + processFolder(directory + "condition_B/"); + + saveResults(table, directory + "output_py.csv") + +# go through all tif files in a given folder and analyse them +def processFolder(folder): + file_list = os.listdir(folder) + + for filename in file_list: + if filename.endswith(".tif"): + processImage(folder + filename) + +# open a given image and process it +def processImage(filename): + + # open image + image = imread(filename) + print(filename) + + # Gaussian blur + blurred_image = filters.gaussian(image, blur_sigma) + + # Thresholding + threshold = filters.threshold_otsu(blurred_image) + print(threshold) + + thresholded_image = blurred_image >= threshold + + # run connected components analysis + label_image = measure.label(thresholded_image) + + + # analyse objects + properties = measure.regionprops(label_image) + count = 1 + + # go through all regions and save results in a table + for property in properties: + y, x = property.centroid + + table[0].extend([filename]) + table[1].extend([count]) + table[2].extend([x]) + table[3].extend([y]) + table[4].extend([property.area]) + + count = count + 1 + +# save a table as CSV file to disc +def saveResults(table, filename): + data_frame = pd.DataFrame(table, ["Filename", "Number", "X", "Y", "Area"]) + data_frame = data_frame.transpose() + data_frame.to_csv(filename) + + +main() \ No newline at end of file