Commit d86eeb8f authored by rhaase's avatar rhaase

initial version of the python/knime/cellprofiler lecture

parent 7df7da5e
// Random image generator
//
// This script expects to 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