예제 #1
0
파일: channel.py 프로젝트: imcf/cecog
    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
예제 #2
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
예제 #3
0
파일: channel.py 프로젝트: waterponey/cecog
    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
예제 #4
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
예제 #5
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
예제 #6
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
예제 #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
예제 #8
0
파일: channel.py 프로젝트: cmci/cecog
    def apply_features(self):

        for strKey, oContainer in self.dctContainers.iteritems():

            oObjectHolder = ObjectHolder(strKey)

            if not oContainer is None:

                for strFeatureCategory in self.lstFeatureCategories:
                    #print strFeatureCategory
                    sys.stdout.flush()
                    oContainer.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']:
                            oContainer.haralick_distance = iHaralickDistance
                            oContainer.applyFeature(strHaralickCategory)

                lstValidObjectIds = []
                lstRejectedObjectIds = []

                for iObjectId, oObject in oContainer.getObjects().iteritems():
                    dctFeatures = oObject.getFeatures()

                    bAcceptObject = True

#                    # post-processing
#                    if self.bPostProcessing:
#
#                        if not eval(self.strPostprocessingConditions, dctFeatures):
#                            if self.bPostProcessDeleteObjects:
#                                #del dctObjects[iObjectId]
#                                oContainer.delObject(iObjectId)
#                                bAcceptObject = False
#                            lstRejectedObjectIds.append(iObjectId)
#                        else:
#                            lstValidObjectIds.append(iObjectId)
#                    else:
#                        lstValidObjectIds.append(iObjectId)
#
#                    oContainer.lstValidObjectIds = lstValidObjectIds
#                    oContainer.lstRejectedObjectIds = lstRejectedObjectIds

                    if bAcceptObject:
                        # build a new ImageObject
                        oImageObject = ImageObject(oObject)
                        oImageObject.iId = iObjectId

                        if self.lstFeatureNames is None:
                            self.lstFeatureNames = sorted(dctFeatures.keys())

                        # assign feature values in sorted order as NumPy array
                        oImageObject.aFeatures = \
                            numpy.asarray(dict_values(dctFeatures,
                                                      self.lstFeatureNames))

                        oObjectHolder[iObjectId] = oImageObject

            if not self.lstFeatureNames is None:
                oObjectHolder.setFeatureNames(self.lstFeatureNames)
            self._dctRegions[strKey] = oObjectHolder