def test_02_03_default_heatmap_values(self):
     module = M.MeasureObjectRadialDistribution()
     module.add_heatmap()
     module.heatmaps[0].image_name.value = IMAGE_NAME
     module.heatmaps[0].object_name.value = OBJECT_NAME
     module.heatmaps[0].bin_count.value = 10
     module.images[0].image_name.value = "Bar"
     module.objects[0].object_name.value = "Foo"
     module.bin_counts[0].bin_count.value = 2
     self.assertEqual(module.heatmaps[0].image_name.get_image_name(), "Bar")
     self.assertFalse(module.heatmaps[0].image_name.is_visible())
     self.assertEqual(module.heatmaps[0].object_name.get_objects_name(),
                      "Foo")
     self.assertFalse(module.heatmaps[0].object_name.is_visible())
     self.assertEqual(module.heatmaps[0].get_number_of_bins(), 2)
     module.add_image()
     self.assertTrue(module.heatmaps[0].image_name.is_visible())
     self.assertEqual(module.heatmaps[0].image_name.get_image_name(),
                      IMAGE_NAME)
     module.add_object()
     self.assertTrue(module.heatmaps[0].object_name.is_visible())
     self.assertEqual(module.heatmaps[0].object_name.get_objects_name(),
                      OBJECT_NAME)
     module.add_bin_count()
     self.assertEqual(module.heatmaps[0].get_number_of_bins(), 10)
Ejemplo n.º 2
0
 def run_module(self, image, labels, center_labels = None, bin_count = 4):
     '''Run the module, returning the measurements
     
     image - matrix representing the image to be analyzed
     labels - labels matrix of objects to be analyzed
     center_labels - labels matrix of alternate centers or None for self
                     centers
     bin_count - # of radial bins
     '''
     module = M.MeasureObjectRadialDistribution()
     module.images[0].image_name.value = IMAGE_NAME
     module.objects[0].object_name.value = OBJECT_NAME
     object_set = cpo.ObjectSet()
     main_objects = cpo.Objects()
     main_objects.segmented = labels
     object_set.add_objects(main_objects, OBJECT_NAME)
     if center_labels is None:
         module.objects[0].center_choice.value = M.C_SELF
     else:
         module.objects[0].center_choice.value = M.C_OTHER
         module.objects[0].center_object_name.value = CENTER_NAME
         center_objects = cpo.Objects()
         center_objects.segmented = center_labels
         object_set.add_objects(center_objects, CENTER_NAME)
     module.bin_counts[0].bin_count.value = bin_count
     pipeline = cpp.Pipeline()
     measurements = cpmeas.Measurements()
     image_set_list = cpi.ImageSetList()
     image_set = image_set_list.get_image_set(0)
     img = cpi.Image(image)
     image_set.add(IMAGE_NAME, img)
     workspace = cpw.Workspace(pipeline, module, image_set, object_set,
                               measurements, image_set_list)
     module.run(workspace)
     return measurements
Ejemplo n.º 3
0
 def run_module(self, image, labels, center_labels = None, 
                center_choice = M.C_CENTERS_OF_OTHER,
                bin_count = 4,
                maximum_radius = 100, wants_scaled = True, 
                wants_workspace=False):
     '''Run the module, returning the measurements
     
     image - matrix representing the image to be analyzed
     labels - labels matrix of objects to be analyzed
     center_labels - labels matrix of alternate centers or None for self
                     centers
     bin_count - # of radial bins
     '''
     module = M.MeasureObjectRadialDistribution()
     module.images[0].image_name.value = IMAGE_NAME
     module.objects[0].object_name.value = OBJECT_NAME
     object_set = cpo.ObjectSet()
     main_objects = cpo.Objects()
     main_objects.segmented = labels
     object_set.add_objects(main_objects, OBJECT_NAME)
     if center_labels is None:
         module.objects[0].center_choice.value = M.C_SELF
     else:
         module.objects[0].center_choice.value = center_choice
         module.objects[0].center_object_name.value = CENTER_NAME
         center_objects = cpo.Objects()
         center_objects.segmented = center_labels
         object_set.add_objects(center_objects, CENTER_NAME)
     module.bin_counts[0].bin_count.value = bin_count
     module.bin_counts[0].wants_scaled.value = wants_scaled
     module.bin_counts[0].maximum_radius.value = maximum_radius
     module.add_heatmap()
     module.add_heatmap()
     module.add_heatmap()
     for i, (a, f) in enumerate(
         ((M.A_FRAC_AT_D, M.F_FRAC_AT_D),
          (M.A_MEAN_FRAC, M.F_MEAN_FRAC),
          (M.A_RADIAL_CV, M.F_RADIAL_CV))):
         module.heatmaps[i].image_name.value = IMAGE_NAME
         module.heatmaps[i].object_name.value = OBJECT_NAME
         module.heatmaps[i].bin_count.value = str(bin_count)
         module.heatmaps[i].wants_to_save_display.value = True
         display_name = HEAT_MAP_NAME+f
         module.heatmaps[i].display_name.value = display_name
         module.heatmaps[i].colormap.value = "gray"
         module.heatmaps[i].measurement.value = a
     pipeline = cpp.Pipeline()
     measurements = cpmeas.Measurements()
     image_set_list = cpi.ImageSetList()
     image_set = measurements
     img = cpi.Image(image)
     image_set.add(IMAGE_NAME, img)
     workspace = cpw.Workspace(pipeline, module, image_set, object_set,
                               measurements, image_set_list)
     module.run(workspace)
     if wants_workspace:
         return measurements, workspace
     return measurements
Ejemplo n.º 4
0
    def test_02_01_get_measurement_columns(self):
        module = M.MeasureObjectRadialDistribution()
        for i, image_name in ((0, "DNA"), (1, "Cytoplasm"), (2, "Actin")):
            if i:
                module.add_image()
            module.images[i].image_name.value = image_name
        for i, object_name, center_name in ((0, "Nucleii", None), (1, "Cells",
                                                                   "Nucleii"),
                                            (2, "Cytoplasm", "Nucleii")):
            if i:
                module.add_object()
            module.objects[i].object_name.value = object_name
            if center_name is None:
                module.objects[i].center_choice.value = M.C_SELF
            else:
                module.objects[i].center_choice.value = M.C_OTHER
                module.objects[i].center_object_name.value = center_name
        for i, bin_count in enumerate((4, 5, 6)):
            if i:
                module.add_bin_count()
            module.bin_counts[i].bin_count.value = bin_count
        module.bin_counts[2].wants_scaled.value = False

        columns = module.get_measurement_columns(None)
        column_dictionary = {}
        for object_name, feature, coltype in columns:
            key = (object_name, feature)
            self.assertFalse(column_dictionary.has_key(key))
            self.assertEqual(coltype, cpmeas.COLTYPE_FLOAT)
            column_dictionary[key] = (object_name, feature, coltype)

        for object_name in [x.object_name.value for x in module.objects]:
            for image_name in [x.image_name.value for x in module.images]:
                for bin_count, wants_scaled in [(x.bin_count.value,
                                                 x.wants_scaled.value)
                                                for x in module.bin_counts]:
                    for bin in range(1,
                                     bin_count + (1 if wants_scaled else 2)):
                        for feature_fn in (feature_frac_at_d,
                                           feature_mean_frac,
                                           feature_radial_cv):
                            measurement = feature_fn(bin, bin_count,
                                                     image_name)
                            key = (object_name, measurement)
                            self.assertTrue(column_dictionary.has_key(key))
                            del column_dictionary[key]
        self.assertEqual(len(column_dictionary), 0)
Ejemplo n.º 5
0
    def test_02_02_get_measurements(self):
        module = M.MeasureObjectRadialDistribution()
        for i, image_name in ((0, "DNA"), (1, "Cytoplasm"), (2, "Actin")):
            if i:
                module.add_image()
            module.images[i].image_name.value = image_name
        for i, object_name, center_name in ((0, "Nucleii", None), (1, "Cells",
                                                                   "Nucleii"),
                                            (2, "Cytoplasm", "Nucleii")):
            if i:
                module.add_object()
            module.objects[i].object_name.value = object_name
            if center_name is None:
                module.objects[i].center_choice.value = M.C_SELF
            else:
                module.objects[i].center_choice.value = M.C_OTHER
                module.objects[i].center_object_name.value = center_name
        for i, bin_count in ((0, 4), (0, 5), (0, 6)):
            if i:
                module.add_bin_count()
            module.bin_counts[i].bin_count.value = bin_count

        for object_name in [x.object_name.value for x in module.objects]:
            self.assertEqual(tuple(module.get_categories(None, object_name)),
                             (M.M_CATEGORY, ))
            for feature in M.F_ALL:
                self.assertTrue(feature in module.get_measurements(
                    None, object_name, M.M_CATEGORY))
            for image_name in [x.image_name.value for x in module.images]:
                for feature in M.F_ALL:
                    self.assertTrue(
                        image_name in module.get_measurement_images(
                            None, object_name, M.M_CATEGORY, feature))
                for bin_count in [
                        x.bin_count.value for x in module.bin_counts
                ]:
                    for bin in range(1, bin_count + 1):
                        for feature in M.F_ALL:
                            self.assertTrue(
                                "%dof%d" %
                                (bin,
                                 bin_count) in module.get_measurement_scales(
                                     None, object_name, M.M_CATEGORY, feature,
                                     image_name))
Ejemplo n.º 6
0
 def test_02_01_get_measurement_columns(self):
     module = M.MeasureObjectRadialDistribution()
     for i,image_name in ((0, "DNA"),(1, "Cytoplasm"),(2,"Actin")):
         if i:
             module.add_image()
         module.images[i].image_name.value = image_name
     for i,object_name, center_name in ((0, "Nucleii", None),
                                        (1, "Cells", "Nucleii"),
                                        (2, "Cytoplasm", "Nucleii")):
         if i:
             module.add_object()
         module.objects[i].object_name.value = object_name
         if center_name is None:
             module.objects[i].center_choice.value = M.C_SELF
         else:
             module.objects[i].center_choice.value = M.C_OTHER
             module.objects[i].center_object_name.value = center_name
     for i,bin_count in ((0,4),(0,5),(0,6)):
         if i:
             module.add_bin_count()
         module.bin_counts[i].bin_count.value = bin_count
     
     columns = module.get_measurement_columns(None)
     column_dictionary = {}
     for object_name, feature, coltype in columns:
         key = (object_name, feature)
         self.assertFalse(column_dictionary.has_key(key))
         self.assertEqual(coltype, cpmeas.COLTYPE_FLOAT)
         column_dictionary[key] = (object_name, feature, coltype)
     
     for object_name in [x.object_name.value for x in module.objects]:
         for image_name in [x.image_name.value for x in module.images]:
             for bin_count in [x.bin_count.value for x in module.bin_counts]:
                 for bin in range(1,bin_count+1):
                     for feature in M.F_ALL:
                         measurement = "_".join((M.M_CATEGORY,
                                                 feature,
                                                 image_name,
                                                 "%dof%d"%(bin, bin_count)))
                         key = (object_name, measurement)
                         self.assertTrue(column_dictionary.has_key(key))
                         del column_dictionary[key]
     self.assertEqual(len(column_dictionary), 0)