Ejemplo n.º 1
0
 def execute(self,
             image,
             function,
             mask=None,
             custom_repeats=None,
             scale=None,
             module=None):
     '''Run the morph module on an input and return the resulting image'''
     INPUT_IMAGE_NAME = 'input'
     OUTPUT_IMAGE_NAME = 'output'
     if module is None:
         module = morph.Morph()
     module.functions[0].function.value = function
     module.image_name.value = INPUT_IMAGE_NAME
     module.output_image_name.value = OUTPUT_IMAGE_NAME
     if custom_repeats is None:
         module.functions[0].repeats_choice.value = morph.R_ONCE
     elif custom_repeats == -1:
         module.functions[0].repeats_choice.value = morph.R_FOREVER
     else:
         module.functions[0].repeats_choice.value = morph.R_CUSTOM
         module.functions[0].custom_repeats.value = custom_repeats
     if scale is not None:
         module.functions[0].scale.value = scale
     pipeline = cpp.Pipeline()
     object_set = cpo.ObjectSet()
     image_set_list = cpi.ImageSetList()
     image_set = image_set_list.get_image_set(0)
     workspace = cpw.Workspace(pipeline, module, image_set, object_set,
                               cpmeas.Measurements(), image_set_list)
     image_set.add(INPUT_IMAGE_NAME, cpi.Image(image, mask=mask))
     module.run(workspace)
     output = image_set.get_image(OUTPUT_IMAGE_NAME)
     return output.pixel_data
Ejemplo n.º 2
0
 def test_04_09_strel_square(self):
     r = np.random.RandomState()
     r.seed(49)
     module = morph.Morph()
     module.functions[0].structuring_element.value = morph.SE_SQUARE
     strel = cpmorph.strel_square(7)
     pixel_data = r.uniform(size=(20, 30)) > .5
     expected = scind.binary_dilation(pixel_data, strel)
     result = self.execute(pixel_data, morph.F_DILATE, scale=7,
                           module=module)
     np.testing.assert_array_equal(expected, result)
Ejemplo n.º 3
0
 def test_04_01_strel_arbitrary(self):
     r = np.random.RandomState()
     r.seed(41)
     strel = r.uniform(size=(5, 3)) > .5
     module = morph.Morph()
     module.functions[0].structuring_element.value = morph.SE_ARBITRARY
     module.functions[0].strel.value_text = cps.BinaryMatrix.to_value(strel)
     pixel_data = r.uniform(size=(20, 30)) > .5
     expected = scind.binary_dilation(pixel_data, strel)
     result = self.execute(pixel_data, morph.F_DILATE, module=module)
     np.testing.assert_array_equal(expected, result)
Ejemplo n.º 4
0
 def test_04_08_strel_disk(self):
     r = np.random.RandomState()
     r.seed(48)
     module = morph.Morph()
     module.functions[0].structuring_element.value = morph.SE_RECTANGLE
     module.functions[0].width.value = 5
     module.functions[0].height.value = 9
     strel = cpmorph.strel_rectangle(5, 9)
     pixel_data = r.uniform(size=(20, 30)) > .5
     expected = scind.binary_dilation(pixel_data, strel)
     result = self.execute(pixel_data, morph.F_DILATE, module=module)
     np.testing.assert_array_equal(expected, result)
Ejemplo n.º 5
0
 def test_04_06_strel_pair(self):
     r = np.random.RandomState()
     r.seed(46)
     module = morph.Morph()
     module.functions[0].structuring_element.value = morph.SE_PAIR
     module.functions[0].x_offset.value = -1
     module.functions[0].y_offset.value = 4
     strel = cpmorph.strel_pair(-1, 4)
     pixel_data = r.uniform(size=(20, 30)) > .5
     expected = scind.binary_dilation(pixel_data, strel)
     result = self.execute(pixel_data, morph.F_DILATE, module=module)
     np.testing.assert_array_equal(expected, result)
Ejemplo n.º 6
0
 def test_04_07_strel_periodicline(self):
     r = np.random.RandomState()
     r.seed(43)
     module = morph.Morph()
     module.functions[0].structuring_element.value = morph.SE_PERIODIC_LINE
     module.functions[0].x_offset.value = 4
     module.functions[0].y_offset.value = -3
     strel = cpmorph.strel_periodicline(4, -3, 3)
     pixel_data = r.uniform(size=(20, 30)) > .5
     expected = scind.binary_dilation(pixel_data, strel)
     result = self.execute(pixel_data, morph.F_DILATE, scale=30,
                           module=module)
     np.testing.assert_array_equal(expected, result)