Example #1
0
    def apply_features(self):
        self._features_calculated = True
        for region_name, container in self.containers.iteritems():
            object_holder = ObjectHolder(region_name)
            if container is not None:

                for group, params in self.feature_groups.iteritems():

                    # XXX special casing for feature parameters.
                    # call pattern like this: cnt.applyFeature(name, params)
                    if group.startswith('haralick'):
                        container.resetHaralick()
                        for dist in params['dist']:
                            container.addHaralickValue(dist)

                    elif group == "spotfeatures":
                        container.spot_diameter = params['diameter']
                        container.spot_threshold = params['thresh']

                    elif group == "granulometry":
                        container.resetGranulometry()
                        for val in params['se']:
                            container.addGranulometryValue(val)

                    container.applyFeature(group)

                for obj_id, c_obj in container.getObjects().iteritems():

                    dctFeatures = c_obj.getFeatures()
                    # build a new ImageObject
                    obj = ImageObject(c_obj)
                    obj.iId = obj_id

                    ul = obj.oRoi.upperLeft
                    crack = [(pos[0] + ul[0], pos[1] + ul[1])
                             for pos in container.getCrackCoordinates(obj_id)]
                    obj.crack_contour = crack

                    # ORIENTATION TEST: orientation of objects (for tracking) #
                    # at the moment a bit of a hack #
                    # The problem is that orientation cannot be a feature #
                    # but moments need to be chosen to calculate the orientation. #
                    if self.feature_groups.has_key('moments'):
                        obj.orientation = Orientation(
                            angle=c_obj.orientation,
                            eccentricity=dctFeatures['eccentricity'])

                    # why do wo sort the features according to their names??
                    # does it matter?
                    if self.lstFeatureNames is None:
                        self.lstFeatureNames = sorted(dctFeatures.keys())

                    # assign feature values in sorted order as NumPy array
                    features = (dctFeatures[f] for f in self.lstFeatureNames)
                    obj.aFeatures = numpy.fromiter(features, dtype=float)
                    object_holder[obj_id] = obj

            if self.lstFeatureNames is not None:
                object_holder.feature_names = self.lstFeatureNames
            self._regions[region_name] = object_holder
Example #2
0
    def apply_features(self):
        self._features_calculated = True
        for region_name, container in self.containers.iteritems():
            object_holder = ObjectHolder(region_name)
            if not container is None:
                for strFeatureCategory in self.lstFeatureCategories:
                    container.applyFeature(strFeatureCategory)

                # calculate set of haralick features
                # (with differnt distances)
                if 'haralick_categories' in self.dctFeatureParameters:
                    for strHaralickCategory in self.dctFeatureParameters[
                            'haralick_categories']:
                        for iHaralickDistance in self.dctFeatureParameters[
                                'haralick_distances']:
                            container.haralick_distance = iHaralickDistance
                            container.applyFeature(strHaralickCategory)

                for obj_id, c_obj in container.getObjects().iteritems():

                    dctFeatures = c_obj.getFeatures()
                    # build a new ImageObject
                    obj = ImageObject(c_obj)
                    obj.iId = obj_id

                    ul = obj.oRoi.upperLeft
                    crack = [(pos[0] + ul[0], pos[1] + ul[1])
                             for pos in container.getCrackCoordinates(obj_id)]
                    obj.crack_contour = crack

                    # ORIENTATION TEST: orientation of objects (for tracking) #
                    # at the moment a bit of a hack #
                    # The problem is that orientation cannot be a feature #
                    # but moments need to be chosen to calculate the orientation. #
                    if 'moments' in self.lstFeatureCategories:
                        obj.orientation = Orientation(
                            angle=c_obj.orientation,
                            eccentricity=dctFeatures['eccentricity'])

                    # why do wo sort the features according to their names??
                    # does it matter?
                    if self.lstFeatureNames is None:
                        self.lstFeatureNames = sorted(dctFeatures.keys())

                    # assign feature values in sorted order as NumPy array
                    features = (dctFeatures[f] for f in self.lstFeatureNames)
                    obj.aFeatures = numpy.fromiter(features, dtype=float)
                    object_holder[obj_id] = obj
                    # print 'orientation %s (%i, %i): %f (%f deg)' % (obj_id,
                    #                                                 obj.oRoi.upperLeft[0],
                    #                                                 obj.oRoi.upperLeft[1],
                    #                                                 obj.orientation,
                    #                                                 180.0 * obj.orientation / numpy.pi)

            if self.lstFeatureNames is not None:
                object_holder.feature_names = self.lstFeatureNames
            self._regions[region_name] = object_holder
Example #3
0
    def apply_features(self):
        self._features_calculated = True
        for region_name, container in self.containers.iteritems():
            object_holder = ObjectHolder(region_name)
            if not container is None:
                for strFeatureCategory in self.lstFeatureCategories:
                    container.applyFeature(strFeatureCategory)

                # calculate set of haralick features
                # (with differnt distances)
                if 'haralick_categories' in self.dctFeatureParameters:
                    for strHaralickCategory in self.dctFeatureParameters['haralick_categories']:
                        for iHaralickDistance in self.dctFeatureParameters['haralick_distances']:
                            container.haralick_distance = iHaralickDistance
                            container.applyFeature(strHaralickCategory)

                for obj_id, c_obj in container.getObjects().iteritems():

                    dctFeatures = c_obj.getFeatures()
                    # build a new ImageObject
                    obj = ImageObject(c_obj)
                    obj.iId = obj_id

                    ul = obj.oRoi.upperLeft
                    crack = [(pos[0] + ul[0], pos[1] + ul[1])
                             for pos in
                             container.getCrackCoordinates(obj_id)]
                    obj.crack_contour = crack


                    # ORIENTATION TEST: orientation of objects (for tracking) #
                    # at the moment a bit of a hack #
                    # The problem is that orientation cannot be a feature #
                    # but moments need to be chosen to calculate the orientation. #
                    if 'moments' in self.lstFeatureCategories:
                        obj.orientation = Orientation(angle = c_obj.orientation,
                                                      eccentricity = dctFeatures['eccentricity'])

                    # why do wo sort the features according to their names??
                    # does it matter?
                    if self.lstFeatureNames is None:
                        self.lstFeatureNames = sorted(dctFeatures.keys())

                    # assign feature values in sorted order as NumPy array
                    features = (dctFeatures[f] for f in self.lstFeatureNames)
                    obj.aFeatures = numpy.fromiter(features, dtype=float)
                    object_holder[obj_id] = obj
                    # print 'orientation %s (%i, %i): %f (%f deg)' % (obj_id,
                    #                                                 obj.oRoi.upperLeft[0],
                    #                                                 obj.oRoi.upperLeft[1],
                    #                                                 obj.orientation,
                    #                                                 180.0 * obj.orientation / numpy.pi)

            if self.lstFeatureNames is not None:
                object_holder.feature_names = self.lstFeatureNames
            self._regions[region_name] = object_holder
Example #4
0
    def apply_features(self):
        self._features_calculated = True
        for region_name, container in self.containers.iteritems():
            object_holder = ObjectHolder(region_name)
            if container is not None:
                for group, params in self.feature_groups.iteritems():
                    if params is None:
                        container.applyFeature(group)
                    else: # special case for haralick features
                        for param in params:
                            container.haralick_distance = param
                            container.applyFeature(group)

                for obj_id, c_obj in container.getObjects().iteritems():

                    dctFeatures = c_obj.getFeatures()
                    # build a new ImageObject
                    obj = ImageObject(c_obj)
                    obj.iId = obj_id

                    ul = obj.oRoi.upperLeft
                    crack = [(pos[0] + ul[0], pos[1] + ul[1])
                             for pos in
                             container.getCrackCoordinates(obj_id)]
                    obj.crack_contour = crack


                    # ORIENTATION TEST: orientation of objects (for tracking) #
                    # at the moment a bit of a hack #
                    # The problem is that orientation cannot be a feature #
                    # but moments need to be chosen to calculate the orientation. #
                    if self.feature_groups.has_key('moments'):
                        obj.orientation = Orientation(
                            angle = c_obj.orientation,
                            eccentricity = dctFeatures['eccentricity']
                            )

                    # why do wo sort the features according to their names??
                    # does it matter?
                    if self.lstFeatureNames is None:
                        self.lstFeatureNames = sorted(dctFeatures.keys())

                    # assign feature values in sorted order as NumPy array
                    features = (dctFeatures[f] for f in self.lstFeatureNames)
                    obj.aFeatures = numpy.fromiter(features, dtype=float)
                    object_holder[obj_id] = obj

            if self.lstFeatureNames is not None:
                object_holder.feature_names = self.lstFeatureNames
            self._regions[region_name] = object_holder
Example #5
0
    def annotate(self, sample_objects, learner, container, region):
        """Annotate predefined class labels to picked samples."""

        training_set = ObjectHolder(region.name)
        training_set.feature_names = region.feature_names

        for class_label, object_ids in sample_objects.iteritems():
            class_name = learner.classdef.names[class_label]
            hex_color = learner.classdef.colors[class_name]

            for obj_id in object_ids:
                obj = region[obj_id]
                obj.iLabel = class_label
                obj.strClassName = class_name
                obj.strHexColor = hex_color
                training_set[obj_id] = obj
        return training_set
Example #6
0
    def annotate(self, sample_objects, learner, container, region):
        """Annotate predefined class labels to picked samples."""

        training_set = ObjectHolder(region.name)
        training_set.feature_names = region.feature_names

        for class_label, object_ids in sample_objects.iteritems():
            class_name = learner.classdef.names[class_label]
            hex_color = learner.classdef.colors[class_name]

            for obj_id in object_ids:
                obj = region[obj_id]
                obj.iLabel = class_label
                obj.strClassName = class_name
                obj.strHexColor = hex_color
                training_set[obj_id] = obj
        return training_set
Example #7
0
    def apply_features(self):
        self._features_calculated = True
        for region_name, container in self.containers.iteritems():
            object_holder = ObjectHolder(region_name)
            if not container is None:                
                container.debug = False
                if container.debug:
                    container.debug_folder = os.path.join("/Users/twalter/temp/spotfeatures", 
                                                          self.meta_image.coordinate.position)
                    if not os.path.exists(container.debug_folder):
                        os.makedirs(container.debug_folder)
                        print 'generated ', container.debug_folder
                    container.debug_prefix = 'img'
                
                # pass parameters to container
                for feature in self.dctFeatureParameters:
                    if feature in ['featurecategory_haralick', 'featurecategory_haralick2']:
                        container.resetHaralick()
                        for haralick_size in self.dctFeatureParameters[feature]['dist']:
                            container.addHaralickValue(haralick_size)
                    elif feature == 'featurecategory_granulometry':
                        container.resetGranulometry()
                        for val in self.dctFeatureParameters[feature]['se']:
                            container.addGranulometryValue(val)
                    elif feature == 'featurecategory_spotfeatures':
                        container.spot_diameter = self.dctFeatureParameters[feature]['diameter']
                        container.spot_threshold = self.dctFeatureParameters[feature]['thresh']
                
                # apply feature                        
                for strFeatureCategory in self.lstFeatureCategories:                    
                    container.applyFeature(strFeatureCategory)

                # ---                
                # to replace
                # calculate set of haralick features
                # (with differnt distances)
#                if 'haralick_categories' in self.dctFeatureParameters:
#                    for strHaralickCategory in self.dctFeatureParameters['haralick_categories']:
#                        for iHaralickDistance in self.dctFeatureParameters['haralick_distances']:
#                            container.haralick_distance = iHaralickDistance
#                            container.applyFeature(strHaralickCategory)
                # ---                

                for obj_id, c_obj in container.getObjects().iteritems():

                    dctFeatures = c_obj.getFeatures()
                    # build a new ImageObject
                    obj = ImageObject(c_obj)
                    obj.iId = obj_id

                    ul = obj.oRoi.upperLeft
                    crack = [(pos[0] + ul[0], pos[1] + ul[1])
                             for pos in
                             container.getCrackCoordinates(obj_id)]
                    obj.crack_contour = crack


                    # ORIENTATION TEST: orientation of objects (for tracking) #
                    # at the moment a bit of a hack #
                    # The problem is that orientation cannot be a feature #
                    # but moments need to be chosen to calculate the orientation. #
                    if 'moments' in self.lstFeatureCategories:
                        obj.orientation = Orientation(angle = c_obj.orientation,
                                                      eccentricity = dctFeatures['eccentricity'])

                    # why do wo sort the features according to their names??
                    # does it matter?
                    if self.lstFeatureNames is None:
                        self.lstFeatureNames = sorted(dctFeatures.keys())

                    # assign feature values in sorted order as NumPy array
                    features = (dctFeatures[f] for f in self.lstFeatureNames)
                    obj.aFeatures = numpy.fromiter(features, dtype=float)
                    object_holder[obj_id] = obj

            if self.lstFeatureNames is not None:
                object_holder.feature_names = self.lstFeatureNames
            self._regions[region_name] = object_holder
Example #8
0
    def apply_features(self):
        self._features_calculated = True
        for region_name, container in self.containers.iteritems():
            object_holder = ObjectHolder(region_name)
            if container is not None:

                for group, params in self.feature_groups.iteritems():

                    # XXX special casing for feature parameters.
                    # call pattern like this: cnt.applyFeature(name, params)
                    if group.startswith('haralick'):
                        container.resetHaralick()
                        for dist in params['dist']:
                            container.addHaralickValue(dist)

                    elif group == "spotfeatures":
                        container.spot_diameter = params['diameter']
                        container.spot_threshold = params['thresh']

                    elif group == "granulometry":
                        container.resetGranulometry()
                        for val in params['se']:
                            container.addGranulometryValue(val)

                    container.applyFeature(group)


                for obj_id, c_obj in container.getObjects().iteritems():

                    dctFeatures = c_obj.getFeatures()
                    # build a new ImageObject
                    obj = ImageObject(c_obj)
                    obj.iId = obj_id

                    ul = obj.oRoi.upperLeft
                    crack = [(pos[0] + ul[0], pos[1] + ul[1])
                             for pos in
                             container.getCrackCoordinates(obj_id)]
                    obj.crack_contour = crack


                    # ORIENTATION TEST: orientation of objects (for tracking) #
                    # at the moment a bit of a hack #
                    # The problem is that orientation cannot be a feature #
                    # but moments need to be chosen to calculate the orientation. #
                    if self.feature_groups.has_key('moments'):
                        obj.orientation = Orientation(
                            angle = c_obj.orientation,
                            eccentricity = dctFeatures['eccentricity']
                        )

                    # why do wo sort the features according to their names??
                    # does it matter?
                    if self.lstFeatureNames is None:
                        self.lstFeatureNames = sorted(dctFeatures.keys())

                    # assign feature values in sorted order as NumPy array
                    features = (dctFeatures[f] for f in self.lstFeatureNames)
                    obj.aFeatures = numpy.fromiter(features, dtype=float)
                    object_holder[obj_id] = obj

            if self.lstFeatureNames is not None:
                object_holder.feature_names = self.lstFeatureNames
            self._regions[region_name] = object_holder
Example #9
0
    def apply_features(self):
        self._features_calculated = True
        for region_name, container in self.containers.iteritems():
            object_holder = ObjectHolder(region_name)
            if not container is None:
                container.debug = False
                if container.debug:
                    container.debug_folder = os.path.join(
                        "/Users/twalter/temp/spotfeatures",
                        self.meta_image.coordinate.position)
                    if not os.path.exists(container.debug_folder):
                        os.makedirs(container.debug_folder)
                        print 'generated ', container.debug_folder
                    container.debug_prefix = 'img'

                # pass parameters to container
                for feature in self.dctFeatureParameters:
                    if feature in [
                            'featurecategory_haralick',
                            'featurecategory_haralick2'
                    ]:
                        container.resetHaralick()
                        for haralick_size in self.dctFeatureParameters[
                                feature]['dist']:
                            container.addHaralickValue(haralick_size)
                    elif feature == 'featurecategory_granulometry':
                        container.resetGranulometry()
                        for val in self.dctFeatureParameters[feature]['se']:
                            container.addGranulometryValue(val)
                    elif feature == 'featurecategory_spotfeatures':
                        container.spot_diameter = self.dctFeatureParameters[
                            feature]['diameter']
                        container.spot_threshold = self.dctFeatureParameters[
                            feature]['thresh']

                # apply feature
                for strFeatureCategory in self.lstFeatureCategories:
                    container.applyFeature(strFeatureCategory)

                # ---
                # to replace
                # calculate set of haralick features
                # (with differnt distances)
#                if 'haralick_categories' in self.dctFeatureParameters:
#                    for strHaralickCategory in self.dctFeatureParameters['haralick_categories']:
#                        for iHaralickDistance in self.dctFeatureParameters['haralick_distances']:
#                            container.haralick_distance = iHaralickDistance
#                            container.applyFeature(strHaralickCategory)
# ---

                for obj_id, c_obj in container.getObjects().iteritems():

                    dctFeatures = c_obj.getFeatures()
                    # build a new ImageObject
                    obj = ImageObject(c_obj)
                    obj.iId = obj_id

                    ul = obj.oRoi.upperLeft
                    crack = [(pos[0] + ul[0], pos[1] + ul[1])
                             for pos in container.getCrackCoordinates(obj_id)]
                    obj.crack_contour = crack

                    # ORIENTATION TEST: orientation of objects (for tracking) #
                    # at the moment a bit of a hack #
                    # The problem is that orientation cannot be a feature #
                    # but moments need to be chosen to calculate the orientation. #
                    if 'moments' in self.lstFeatureCategories:
                        obj.orientation = Orientation(
                            angle=c_obj.orientation,
                            eccentricity=dctFeatures['eccentricity'])

                    # why do wo sort the features according to their names??
                    # does it matter?
                    if self.lstFeatureNames is None:
                        self.lstFeatureNames = sorted(dctFeatures.keys())

                    # assign feature values in sorted order as NumPy array
                    features = (dctFeatures[f] for f in self.lstFeatureNames)
                    obj.aFeatures = numpy.fromiter(features, dtype=float)
                    object_holder[obj_id] = obj

            if self.lstFeatureNames is not None:
                object_holder.feature_names = self.lstFeatureNames
            self._regions[region_name] = object_holder