-
-
Save bennihepp/1646457 to your computer and use it in GitHub Desktop.
Example script for CellProfiler RunScript module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cpscript | |
from scipy import ndimage | |
# either ask explicitely for an object | |
labels = cpscript.objects['Cells'].segmented | |
# or ask the user to choose one | |
# cpscript.objects.input_objects.require('The objects from which to measure the distance') | |
#labels = cpscript.objects.input_objects.segmented | |
background_labels = np.array(labels == 0, dtype=int) | |
dt_labels = ndimage.distance_transform_edt(background_labels) | |
# same with images etc. | |
imVSVG_pixels = cpscript.images['imVSVG'].pixel_data | |
# or again ask the user | |
# cpscript.images.input_image.require('The image to multiply with the distance transformed object-image') | |
# imVSVG_pixels = cpscript.images.input_image.pixel_data | |
imVSVG_dt_pixels = imVSVG_pixels * dt_labels | |
imVSVG_dr_pixels = imVSVG_pixels / dt_labels | |
imVSVG_dr_pixels[dt_labels == 0] = imVSVG_pixels[dt_labels == 0] | |
# output can also be provided in two ways | |
cpscript.images['imVSVG_dr_pixels'].pixel_data = imVSVG_dr_pixels | |
# here the user can name the output object within cellprofiler | |
# cpscript.images.output_image.provide('Name the output image') | |
# cpscript.images.output_image.pixel_data = imVSVG_dr_pixels |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment