Last active
July 20, 2016 00:40
-
-
Save 0x00b1/c74ba014a7ae4bff181bec3a632a9613 to your computer and use it in GitHub Desktop.
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
| """ | |
| Blob detection | |
| """ | |
| import skimage.data | |
| import skimage.draw | |
| import skimage.feature | |
| import cellprofiler.cpimage | |
| import cellprofiler.cpmodule | |
| import cellprofiler.settings | |
| import matplotlib.pyplot | |
| import numpy | |
| class BlobDetection(cellprofiler.cpmodule.CPModule): | |
| module_name = "BlobDetection" | |
| category = "Feature detection" | |
| variable_revision_number = 1 | |
| def create_settings(self): | |
| self.input = cellprofiler.settings.ImageNameSubscriber( | |
| "Input image name:" | |
| ) | |
| self.output = cellprofiler.settings.ImageNameProvider( | |
| "Output image name:" | |
| ) | |
| self.operation = cellprofiler.settings.Choice( | |
| "Operation", | |
| [ | |
| "Determinant of Hessian (DoH)", | |
| "Difference of Gaussians (DoG)", | |
| "Laplacian of Gaussian (LoG)", | |
| "Maximally stable extremal regions (MSER)", | |
| "Principal curvature-based region detector (PCBR)" | |
| ] | |
| ) | |
| self.minimum_sigma = cellprofiler.settings.Integer( | |
| "Minimum sigma", | |
| 1, | |
| minval = 1, | |
| maxval = 100, | |
| ) | |
| self.maximum_sigma = cellprofiler.settings.Integer( | |
| "Maximum sigma", | |
| 30, | |
| minval = 1, | |
| maxval = 100, | |
| ) | |
| self.intermediate_values_of_standard_deviations = cellprofiler.settings.Integer( | |
| "Intermediate values of standard deviations", | |
| 10, | |
| minval=1, | |
| maxval=100, | |
| ) | |
| self.threshold = cellprofiler.settings.Float( | |
| "Threshold", | |
| 0.01, | |
| minval=0.01, | |
| maxval=1.00, | |
| ) | |
| def settings(self): | |
| return [ | |
| self.input, | |
| self.output, | |
| self.operation, | |
| self.minimum_sigma, | |
| self.maximum_sigma, | |
| self.intermediate_values_of_standard_deviations, | |
| self.threshold | |
| ] | |
| def visible_settings(self): | |
| settings = [ | |
| self.input, | |
| self.output, | |
| self.operation, | |
| ] | |
| if self.operation in [ | |
| "Determinant of Hessian (DoH)", | |
| "Difference of Gaussians (DoG)", | |
| "Laplacian of Gaussian (LoG)" | |
| ]: | |
| settings = settings + [ | |
| self.minimum_sigma, | |
| self.maximum_sigma, | |
| self.intermediate_values_of_standard_deviations, | |
| self.threshold | |
| ] | |
| return settings | |
| def run(self, workspace): | |
| input_image_name = self.input.value | |
| output_image_name = self.output.value | |
| image_set = workspace.image_set | |
| input_image = image_set.get_image(input_image_name, must_be_grayscale=True) | |
| pixels = input_image.pixel_data | |
| blobs = None | |
| if self.operation == "Determinant of Hessian (DoH)": | |
| blobs = skimage.feature.blob_doh( | |
| image=pixels, | |
| min_sigma=self.minimum_sigma.value, | |
| max_sigma=self.maximum_sigma.value, | |
| num_sigma=self.intermediate_values_of_standard_deviations.value, | |
| threshold=self.threshold.value | |
| ) | |
| elif self.operation == "Difference of Gaussians (DoG)": | |
| blobs = skimage.feature.blob_dog( | |
| image=pixels, | |
| min_sigma=self.minimum_sigma.value, | |
| max_sigma=self.maximum_sigma.value, | |
| threshold=self.threshold.value | |
| ) | |
| elif self.operation == "Laplacian of Gaussian (LoG)": | |
| blobs = skimage.feature.blob_log( | |
| image=pixels, | |
| min_sigma=self.minimum_sigma.value, | |
| max_sigma=self.maximum_sigma.value, | |
| num_sigma=self.intermediate_values_of_standard_deviations.value, | |
| threshold=self.threshold.value | |
| ) | |
| elif self.operation == "Maximally stable extremal regions (MSER)": | |
| pass | |
| elif self.operation == "Principal curvature-based region detector (PCBR)": | |
| pass | |
| else: | |
| pass | |
| output_image = cellprofiler.cpimage.Image(skimage.data.camera(), parent_image=input_image) | |
| image_set.add(output_image_name, output_image) | |
| if self.show_window: | |
| workspace.display_data.input = pixels | |
| workspace.display_data.blobs = blobs | |
| workspace.display_data.output = skimage.data.camera() | |
| def display(self, workspace, figure): | |
| dimensions = (2, 1) | |
| figure.set_subplots(dimensions) | |
| figure.subplot_imshow_grayscale( | |
| 0, | |
| 0, | |
| workspace.display_data.input | |
| ) | |
| output = figure.subplot_imshow_grayscale( | |
| 1, | |
| 0, | |
| workspace.display_data.input | |
| ) | |
| blobs = workspace.display_data.blobs | |
| blobs[:, 2] = blobs[:, 2] * numpy.sqrt(2) | |
| for blob in blobs: | |
| y, x, r = blob | |
| circle = matplotlib.pyplot.Circle((x, y), r, color="red", linewidth=1, fill=False) | |
| output.add_patch(circle) |
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
| # coding=utf-8 | |
| """ | |
| Corner detection | |
| """ | |
| import skimage.data | |
| import skimage.draw | |
| import skimage.feature | |
| import cellprofiler.cpimage | |
| import cellprofiler.cpmodule | |
| import cellprofiler.settings | |
| class CornerDetection(cellprofiler.cpmodule.CPModule): | |
| module_name = "CornerDetection" | |
| category = "Feature detection" | |
| variable_revision_number = 1 | |
| def create_settings(self): | |
| self.input = cellprofiler.settings.ImageNameSubscriber( | |
| "Input image name:" | |
| ) | |
| self.output = cellprofiler.settings.ImageNameProvider( | |
| "Output image name:" | |
| ) | |
| self.operation = cellprofiler.settings.Choice( | |
| "Operation", | |
| [ | |
| "Harris", | |
| "Shi and Tomasi" | |
| ] | |
| ) | |
| self.sigma = cellprofiler.settings.Float( | |
| "Sigma", | |
| 1, | |
| minval = 0.01, | |
| maxval = 1.0, | |
| ) | |
| def settings(self): | |
| return [ | |
| self.input, | |
| self.output, | |
| self.operation, | |
| self.sigma | |
| ] | |
| def visible_settings(self): | |
| settings = [ | |
| self.input, | |
| self.output, | |
| self.operation, | |
| ] | |
| if self.operation == "Harris": | |
| settings = settings + [ | |
| self.sigma | |
| ] | |
| if self.operation == "Shi and Tomasi": | |
| settings = settings + [ | |
| self.sigma | |
| ] | |
| return settings | |
| def run(self, workspace): | |
| input_image_name = self.input.value | |
| output_image_name = self.output.value | |
| image_set = workspace.image_set | |
| input_image = image_set.get_image(input_image_name, must_be_grayscale=True) | |
| pixels = input_image.pixel_data | |
| corners = None | |
| if self.operation == "Harris": | |
| corners = skimage.feature.corner_harris( | |
| image=pixels | |
| ) | |
| elif self.operation == "Shi and Tomasi": | |
| corners = skimage.feature.corner_shi_tomasi( | |
| image=pixels, | |
| sigma=self.sigma.value | |
| ) | |
| else: | |
| pass | |
| output_image = cellprofiler.cpimage.Image(skimage.data.camera(), parent_image=input_image) | |
| image_set.add(output_image_name, output_image) | |
| if self.show_window: | |
| workspace.display_data.input = pixels | |
| workspace.display_data.output = corners | |
| def display(self, workspace, figure): | |
| dimensions = (2, 1) | |
| figure.set_subplots(dimensions) | |
| figure.subplot_imshow_grayscale( | |
| 0, | |
| 0, | |
| workspace.display_data.input | |
| ) | |
| output = figure.subplot_imshow_grayscale( | |
| 1, | |
| 0, | |
| workspace.display_data.output | |
| ) |
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
| """ | |
| Edge detection | |
| """ | |
| import skimage.data | |
| import skimage.draw | |
| import skimage.feature | |
| import skimage.filters | |
| import cellprofiler.cpimage | |
| import cellprofiler.cpmodule | |
| import cellprofiler.settings | |
| class EdgeDetection(cellprofiler.cpmodule.CPModule): | |
| module_name = "EdgeDetection" | |
| category = "Feature detection" | |
| variable_revision_number = 1 | |
| def create_settings(self): | |
| self.input = cellprofiler.settings.ImageNameSubscriber( | |
| "Input image name:" | |
| ) | |
| self.output = cellprofiler.settings.ImageNameProvider( | |
| "Output image name:" | |
| ) | |
| self.operation = cellprofiler.settings.Choice( | |
| "Operation", | |
| [ | |
| "Canny", | |
| "Sobel" | |
| ] | |
| ) | |
| self.sigma = cellprofiler.settings.Float( | |
| "Sigma", | |
| 0.01, | |
| minval=0.01, | |
| maxval=1.00, | |
| ) | |
| def settings(self): | |
| return [ | |
| self.input, | |
| self.output, | |
| self.operation, | |
| self.sigma | |
| ] | |
| def visible_settings(self): | |
| settings = [ | |
| self.input, | |
| self.output, | |
| self.operation, | |
| ] | |
| if self.operation == "Canny": | |
| settings = settings + [ | |
| self.sigma | |
| ] | |
| return settings | |
| def run(self, workspace): | |
| input_image_name = self.input.value | |
| output_image_name = self.output.value | |
| image_set = workspace.image_set | |
| input_image = image_set.get_image(input_image_name, must_be_grayscale=True) | |
| pixels = input_image.pixel_data | |
| edges = None | |
| if self.operation == "Canny": | |
| edges = skimage.feature.canny( | |
| image=pixels, | |
| sigma=self.sigma.value | |
| ) | |
| elif self.operation == "Sobel": | |
| edges = skimage.filters.sobel( | |
| image=pixels | |
| ) | |
| else: | |
| pass | |
| if self.show_window: | |
| workspace.display_data.input = pixels | |
| workspace.display_data.output = edges | |
| def display(self, workspace, figure): | |
| dimensions = (2, 1) | |
| figure.set_subplots(dimensions) | |
| figure.subplot_imshow_grayscale( | |
| 0, | |
| 0, | |
| workspace.display_data.input | |
| ) | |
| output = figure.subplot_imshow_grayscale( | |
| 1, | |
| 0, | |
| workspace.display_data.output | |
| ) |
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
| """ | |
| Gradient | |
| """ | |
| import cellprofiler.cpimage | |
| import cellprofiler.cpmodule | |
| import cellprofiler.settings | |
| import skimage.filters.rank | |
| import skimage.morphology | |
| class Gradient(cellprofiler.cpmodule.CPModule): | |
| module_name = "Gradient" | |
| category = "Image processing" | |
| variable_revision_number = 1 | |
| def create_settings(self): | |
| self.input = cellprofiler.settings.ImageNameSubscriber( | |
| "Input image name:" | |
| ) | |
| self.output = cellprofiler.settings.ImageNameProvider( | |
| "Output image name:" | |
| ) | |
| def settings(self): | |
| return [ | |
| self.input, | |
| self.output | |
| ] | |
| def visible_settings(self): | |
| settings = [ | |
| self.input, | |
| self.output | |
| ] | |
| return settings | |
| def run(self, workspace): | |
| input_image_name = self.input.value | |
| output_image_name = self.output.value | |
| image_set = workspace.image_set | |
| input_image = image_set.get_image(input_image_name, must_be_grayscale=True) | |
| pixels = input_image.pixel_data | |
| disk = skimage.morphology.disk(5) | |
| output_data = skimage.filters.rank.gradient(pixels, disk) < 10 | |
| output_image = cellprofiler.cpimage.Image(output_data, parent_image=input_image) | |
| image_set.add(output_image_name, output_image) | |
| if self.show_window: | |
| workspace.display_data.input = pixels | |
| workspace.display_data.output_data = output_data | |
| def display(self, workspace, figure): | |
| dimensions = (2, 1) | |
| figure.set_subplots(dimensions) | |
| figure.subplot_imshow_grayscale( | |
| 0, | |
| 0, | |
| workspace.display_data.input | |
| ) | |
| figure.subplot_imshow_grayscale( | |
| 1, | |
| 0, | |
| workspace.display_data.output_data | |
| ) |
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
| """ | |
| Graph partition | |
| """ | |
| import skimage.data | |
| import skimage.draw | |
| import skimage.feature | |
| import skimage.filters | |
| import cellprofiler.cpimage | |
| import cellprofiler.cpmodule | |
| import cellprofiler.settings | |
| class GraphPartition(cellprofiler.cpmodule.CPModule): | |
| module_name = "GraphPartition" | |
| category = "Image segmentation" | |
| variable_revision_number = 1 | |
| def create_settings(self): | |
| self.input = cellprofiler.settings.ImageNameSubscriber( | |
| "Input image name:" | |
| ) | |
| self.output = cellprofiler.settings.ImageNameProvider( | |
| "Output image name:" | |
| ) | |
| self.operation = cellprofiler.settings.Choice( | |
| "Operation", | |
| [ | |
| "Random walker algorithm" | |
| ] | |
| ) | |
| def settings(self): | |
| return [ | |
| self.input, | |
| self.output, | |
| self.operation | |
| ] | |
| def visible_settings(self): | |
| settings = [ | |
| self.input, | |
| self.output, | |
| self.operation | |
| ] | |
| return settings | |
| def run(self, workspace): | |
| input_image_name = self.input.value | |
| output_image_name = self.output.value | |
| image_set = workspace.image_set | |
| input_image = image_set.get_image(input_image_name, must_be_grayscale=True) | |
| pixels = input_image.pixel_data | |
| if self.operation == "Random walker algorithm": | |
| pass | |
| else: | |
| pass | |
| if self.show_window: | |
| workspace.display_data.input = pixels | |
| def display(self, workspace, figure): | |
| dimensions = (2, 1) | |
| figure.set_subplots(dimensions) | |
| figure.subplot_imshow_grayscale( | |
| 0, | |
| 0, | |
| workspace.display_data.input | |
| ) | |
| output = figure.subplot_imshow_grayscale( | |
| 1, | |
| 0, | |
| workspace.display_data.output | |
| ) |
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
| """ | |
| Graph partition | |
| """ | |
| import skimage.data | |
| import skimage.draw | |
| import skimage.feature | |
| import skimage.filters | |
| import cellprofiler.cpimage | |
| import cellprofiler.cpmodule | |
| import cellprofiler.settings | |
| class RegionGrowing(cellprofiler.cpmodule.CPModule): | |
| module_name = "RegionGrowing" | |
| category = "Image segmentation" | |
| variable_revision_number = 1 | |
| def create_settings(self): | |
| self.input = cellprofiler.settings.ImageNameSubscriber( | |
| "Input image name:" | |
| ) | |
| self.output = cellprofiler.settings.ImageNameProvider( | |
| "Output image name:" | |
| ) | |
| self.operation = cellprofiler.settings.Choice( | |
| "Operation", | |
| [ | |
| "Random walker algorithm" | |
| ] | |
| ) | |
| def settings(self): | |
| return [ | |
| self.input, | |
| self.output, | |
| self.operation | |
| ] | |
| def visible_settings(self): | |
| settings = [ | |
| self.input, | |
| self.output, | |
| self.operation | |
| ] | |
| return settings | |
| def run(self, workspace): | |
| input_image_name = self.input.value | |
| output_image_name = self.output.value | |
| image_set = workspace.image_set | |
| input_image = image_set.get_image(input_image_name, must_be_grayscale=True) | |
| pixels = input_image.pixel_data | |
| if self.operation == "Random walker algorithm": | |
| pass | |
| else: | |
| pass | |
| if self.show_window: | |
| workspace.display_data.input = pixels | |
| def display(self, workspace, figure): | |
| dimensions = (2, 1) | |
| figure.set_subplots(dimensions) | |
| figure.subplot_imshow_grayscale( | |
| 0, | |
| 0, | |
| workspace.display_data.input | |
| ) | |
| output = figure.subplot_imshow_grayscale( | |
| 1, | |
| 0, | |
| workspace.display_data.output | |
| ) |
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
| """ | |
| Ridge detection | |
| """ | |
| import skimage.data | |
| import skimage.draw | |
| import skimage.feature | |
| import cellprofiler.cpimage | |
| import cellprofiler.cpmodule | |
| import cellprofiler.settings | |
| import matplotlib.pyplot | |
| import numpy | |
| class RidgeDetection(cellprofiler.cpmodule.CPModule): | |
| module_name = "RidgeDetection" | |
| category = "Feature detection" | |
| variable_revision_number = 1 | |
| def create_settings(self): | |
| self.input = cellprofiler.settings.ImageNameSubscriber( | |
| "Input image name:" | |
| ) | |
| self.output = cellprofiler.settings.ImageNameProvider( | |
| "Output image name:" | |
| ) | |
| self.operation = cellprofiler.settings.Choice( | |
| "Operation", | |
| [ | |
| "Determinant of Hessian (DoH)", | |
| "Difference of Gaussians (DoG)", | |
| "Laplacian of Gaussian (LoG)", | |
| "Maximally stable extremal regions (MSER)", | |
| "Principal curvature-based region detector (PCBR)" | |
| ] | |
| ) | |
| self.minimum_sigma = cellprofiler.settings.Integer( | |
| "Minimum sigma", | |
| 1, | |
| minval = 1, | |
| maxval = 100, | |
| ) | |
| self.maximum_sigma = cellprofiler.settings.Integer( | |
| "Maximum sigma", | |
| 30, | |
| minval = 1, | |
| maxval = 100, | |
| ) | |
| self.intermediate_values_of_standard_deviations = cellprofiler.settings.Integer( | |
| "Intermediate values of standard deviations", | |
| 10, | |
| minval=1, | |
| maxval=100, | |
| ) | |
| self.threshold = cellprofiler.settings.Float( | |
| "Threshold", | |
| 0.01, | |
| minval=0.01, | |
| maxval=1.00, | |
| ) | |
| def settings(self): | |
| return [ | |
| self.input, | |
| self.output, | |
| self.operation, | |
| self.minimum_sigma, | |
| self.maximum_sigma, | |
| self.intermediate_values_of_standard_deviations, | |
| self.threshold | |
| ] | |
| def visible_settings(self): | |
| settings = [ | |
| self.input, | |
| self.output, | |
| self.operation, | |
| ] | |
| if self.operation in [ | |
| "Determinant of Hessian (DoH)", | |
| "Difference of Gaussians (DoG)", | |
| "Laplacian of Gaussian (LoG)" | |
| ]: | |
| settings = settings + [ | |
| self.minimum_sigma, | |
| self.maximum_sigma, | |
| self.intermediate_values_of_standard_deviations, | |
| self.threshold | |
| ] | |
| return settings | |
| def run(self, workspace): | |
| input_image_name = self.input.value | |
| output_image_name = self.output.value | |
| image_set = workspace.image_set | |
| input_image = image_set.get_image(input_image_name, must_be_grayscale=True) | |
| pixels = input_image.pixel_data | |
| blobs = None | |
| if self.operation == "Determinant of Hessian (DoH)": | |
| blobs = skimage.feature.blob_doh( | |
| image=pixels, | |
| min_sigma=self.minimum_sigma.value, | |
| max_sigma=self.maximum_sigma.value, | |
| num_sigma=self.intermediate_values_of_standard_deviations.value, | |
| threshold=self.threshold.value | |
| ) | |
| elif self.operation == "Difference of Gaussians (DoG)": | |
| blobs = skimage.feature.blob_dog( | |
| image=pixels, | |
| min_sigma=self.minimum_sigma.value, | |
| max_sigma=self.maximum_sigma.value, | |
| threshold=self.threshold.value | |
| ) | |
| elif self.operation == "Laplacian of Gaussian (LoG)": | |
| blobs = skimage.feature.blob_log( | |
| image=pixels, | |
| min_sigma=self.minimum_sigma.value, | |
| max_sigma=self.maximum_sigma.value, | |
| num_sigma=self.intermediate_values_of_standard_deviations.value, | |
| threshold=self.threshold.value | |
| ) | |
| elif self.operation == "Maximally stable extremal regions (MSER)": | |
| pass | |
| elif self.operation == "Principal curvature-based region detector (PCBR)": | |
| pass | |
| else: | |
| pass | |
| output_image = cellprofiler.cpimage.Image(skimage.data.camera(), parent_image=input_image) | |
| image_set.add(output_image_name, output_image) | |
| if self.show_window: | |
| workspace.display_data.input = pixels | |
| workspace.display_data.blobs = blobs | |
| workspace.display_data.output = skimage.data.camera() | |
| def display(self, workspace, figure): | |
| dimensions = (2, 1) | |
| figure.set_subplots(dimensions) | |
| figure.subplot_imshow_grayscale( | |
| 0, | |
| 0, | |
| workspace.display_data.input | |
| ) | |
| output = figure.subplot_imshow_grayscale( | |
| 1, | |
| 0, | |
| workspace.display_data.input | |
| ) | |
| blobs = workspace.display_data.blobs | |
| blobs[:, 2] = blobs[:, 2] * numpy.sqrt(2) | |
| for blob in blobs: | |
| y, x, r = blob | |
| circle = matplotlib.pyplot.Circle((x, y), r, color="red", linewidth=1, fill=False) | |
| output.add_patch(circle) |
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
| """ | |
| Thresholding | |
| """ | |
| import cellprofiler.cpimage | |
| import cellprofiler.cpmodule | |
| import cellprofiler.settings | |
| import skimage.filters | |
| class Thresholding(cellprofiler.cpmodule.CPModule): | |
| module_name = "Thresholding" | |
| category = "Image segmentation" | |
| variable_revision_number = 1 | |
| def create_settings(self): | |
| self.input = cellprofiler.settings.ImageNameSubscriber( | |
| "Input image name:" | |
| ) | |
| self.output = cellprofiler.settings.ImageNameProvider( | |
| "Output image name:" | |
| ) | |
| def settings(self): | |
| return [ | |
| self.input, | |
| self.output | |
| ] | |
| def visible_settings(self): | |
| settings = [ | |
| self.input, | |
| self.output | |
| ] | |
| return settings | |
| def run(self, workspace): | |
| input_image_name = self.input.value | |
| output_image_name = self.output.value | |
| image_set = workspace.image_set | |
| input_image = image_set.get_image(input_image_name, must_be_grayscale=True) | |
| input = input_image.pixel_data | |
| threshold = skimage.filters.threshold_otsu(input) | |
| output = input > threshold | |
| if self.show_window: | |
| workspace.display_data.input = input | |
| workspace.display_data.output = output | |
| def display(self, workspace, figure): | |
| dimensions = (2, 1) | |
| figure.set_subplots(dimensions) | |
| figure.subplot_imshow_grayscale( | |
| 0, | |
| 0, | |
| workspace.display_data.input | |
| ) | |
| output = figure.subplot_imshow_grayscale( | |
| 1, | |
| 0, | |
| workspace.display_data.output | |
| ) |
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
| """ | |
| Watershed | |
| """ | |
| import skimage.data | |
| import skimage.draw | |
| import skimage.feature | |
| import skimage.filters | |
| import cellprofiler.cpimage | |
| import cellprofiler.cpmodule | |
| import cellprofiler.settings | |
| import skimage.morphology | |
| import scipy.ndimage | |
| class Watershed(cellprofiler.cpmodule.CPModule): | |
| module_name = "Watershed" | |
| category = "Image segmentation" | |
| variable_revision_number = 1 | |
| def create_settings(self): | |
| self.input = cellprofiler.settings.ImageNameSubscriber( | |
| "Input image name:" | |
| ) | |
| self.markers = cellprofiler.settings.ImageNameSubscriber( | |
| "Markers:" | |
| ) | |
| self.output = cellprofiler.settings.ImageNameProvider( | |
| "Output image name:" | |
| ) | |
| def settings(self): | |
| return [ | |
| self.input, | |
| self.markers, | |
| self.output | |
| ] | |
| def visible_settings(self): | |
| settings = [ | |
| self.input, | |
| self.markers, | |
| self.output | |
| ] | |
| return settings | |
| def run(self, workspace): | |
| input_image_name = self.input.value | |
| markers_name = self.markers.value | |
| output_image_name = self.output.value | |
| image_set = workspace.image_set | |
| input_image = image_set.get_image(input_image_name, must_be_grayscale=True) | |
| markers_image = image_set.get_image(markers_name, must_be_grayscale=True) | |
| input_image_data = input_image.pixel_data | |
| markers_image_data = markers_image.pixel_data | |
| markers_labels = scipy.ndimage.label(markers_image_data)[0] | |
| output_image_data = skimage.morphology.watershed(input_image_data, markers_labels) | |
| if self.show_window: | |
| workspace.display_data.input_image_data = input_image_data | |
| workspace.display_data.markers_image_data = markers_image_data | |
| workspace.display_data.output_image_data = output_image_data | |
| def display(self, workspace, figure): | |
| dimensions = (3, 1) | |
| figure.set_subplots(dimensions) | |
| figure.subplot_imshow_grayscale( | |
| 0, | |
| 0, | |
| workspace.display_data.input_image_data | |
| ) | |
| figure.subplot_imshow_grayscale( | |
| 1, | |
| 0, | |
| workspace.display_data.markers_image_data | |
| ) | |
| figure.subplot_imshow_grayscale( | |
| 2, | |
| 0, | |
| workspace.display_data.output_image_data | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment