コード例 #1
0
ファイル: cecog_batch.py プロジェクト: imcf/cecog
    path_output = options.output

    if path_input is not None:
        settings.set2('pathin', path_input)
        logger.info('Overwrite input path by %s' % path_input)
    else:
        path_input = settings.get2('pathin')
    if path_output is not None:
        settings.set2('pathout', path_output)
        logger.info('Overwrite output path by %s' % path_output)
    else:
        path_output = settings.get2('pathout')


    if multiple_plates is None:
        multiple_plates = settings.get(SECTION_NAME_GENERAL, 'has_multiple_plates')
    else:
        logger.info('Overwrite has_multiple_plates by %s' % multiple_plates)


    imagecontainer = ImageContainer()
    imagecontainer.import_from_settings(settings)

    # FIXME: Could be more generally specified. SGE is setting the job item index via an environment variable
    if index is None:
        pass
    elif index.isdigit():
        index = int(index)
    else:
        if index == ENV_INDEX_SGE:
            logger.info("Using SGE job item index: environment variable '%s'" % index)
コード例 #2
0
ファイル: cecog_batch.py プロジェクト: bobi5rova/cecog
    path_output = options.output

    if path_input is not None:
        settings.set2('pathin', path_input)
        logger.info('Overwrite input path by %s' % path_input)
    else:
        path_input = settings.get2('pathin')
    if path_output is not None:
        settings.set2('pathout', path_output)
        logger.info('Overwrite output path by %s' % path_output)
    else:
        path_output = settings.get2('pathout')


    if multiple_plates is None:
        multiple_plates = settings.get(SECTION_NAME_GENERAL, 'has_multiple_plates')
    else:
        logger.info('Overwrite has_multiple_plates by %s' % multiple_plates)


    imagecontainer = ImageContainer()
    imagecontainer.import_from_settings(settings)

    # FIXME: Could be more generally specified. SGE is setting the job item index via an environment variable
    if index is None:
        pass
    elif index.isdigit():
        index = int(index)
    else:
        if index == ENV_INDEX_SGE:
            logger.info("Using SGE job item index: environment variable '%s'" % index)
コード例 #3
0
ファイル: cmdtool.py プロジェクト: manerotoni/cecog
class SettingsMapper(object):
    """Map parameters from a ConfigSettings instance to groups to fit
    the API"""

    CHANNEL_CLASSES = (PrimaryChannel, SecondaryChannel, TertiaryChannel)

    FEATURES = {'featurecategory_intensity': ['normbase', 'normbase2'],
                'featurecategory_haralick': ['haralick', 'haralick2'],
                'featurecategory_stat_geom': ['levelset'],
                'featurecategory_granugrey': ['granulometry'],
                'featurecategory_basicshape': ['roisize',
                                               'circularity',
                                               'irregularity',
                                               'irregularity2',
                                               'axes'],
                'featurecategory_convhull': ['convexhull'],
                'featurecategory_distance': ['distance'],
                'featurecategory_moments': ['moments']}

    def __init__(self, configfile):
        self.img_height = None
        self.img_width = None
        self.settings = ConfigSettings()
        self.settings.read(configfile)

    def __call__(self, section, param):
        return self.settings.get(section, param)

    def setImageSize(self, width, height):
        self.img_width = width
        self.img_height = height

    @property
    def img_size(self):
        return self.img_width, self.img_height

    def featureParams(self, ch_name="Primary"):
        f_categories = list()
        f_cat_params = dict()

        # unfortunateley some classes expect empty list and dict
        if ch_name.lower() in CH_VIRTUAL:
            return f_categories, f_cat_params

        for cat, feature in self.FEATURES.iteritems():
            featopt = '%s_%s' %(ch_name, cat)
            if self('FeatureExtraction', featopt):
                if "haralick" in cat:
                    try:
                        f_cat_params['haralick_categories'].extend(feature)
                    except KeyError:
                        assert isinstance(feature, list)
                        f_cat_params['haralick_categories'] = feature
                else:
                    f_categories += feature

        if f_cat_params.has_key("haralick_categories"):
            f_cat_params['haralick_distances'] = (1, 2, 4, 8)

        return f_categories, f_cat_params

    def zsliceParams(self, chname):
        self.settings.set_section('ObjectDetection')
        if self("ObjectDetection", "%s_%s" %(chname.lower(), 'zslice_selection')):
            par = self("ObjectDetection", "%s_%s" %(chname.lower(), 'zslice_selection_slice'))
        elif self("ObjectDetection", "%s_%s" %(chname.lower(), 'zslice_projection')):
            method = self("ObjectDetection", "%s_%s" %(chname.lower(), 'zslice_projection_method'))
            begin = self("ObjectDetection", "%s_%s" %(chname.lower(), 'zslice_projection_begin'))
            end = self("ObjectDetection", "%s_%s" %(chname.lower(), 'zslice_projection_end'))
            step = self("ObjectDetection", "%s_%s" %(chname.lower(), 'zslice_projection_step'))
            par = (method, begin, end, step)
        return par

    def registrationShift(self):
        xs = [0]
        ys = [0]

        for prefix in (SecondaryChannel.PREFIX, TertiaryChannel.PREFIX):
            if self('General','process_%s' %prefix):
                reg_x = self('ObjectDetection', '%s_channelregistration_x' %prefix)
                reg_y = self('ObjectDetection', '%s_channelregistration_y' %prefix)
                xs.append(reg_x)
                ys.append(reg_y)

        diff_x = []
        diff_y = []
        for i in range(len(xs)):
            for j in range(i, len(xs)):
                diff_x.append(abs(xs[i]-xs[j]))
                diff_y.append(abs(ys[i]-ys[j]))

        if self('General', 'crop_image'):
            y0 = self('General', 'crop_image_y0')
            y1 = self('General', 'crop_image_y1')
            x0 = self('General', 'crop_image_x0')
            x1 = self('General', 'crop_image_x1')

            self.img_width = x1 - x0
            self.img_height = y1 - y0

        if self.img_height is None or self.img_width is None:
            raise RuntimeError("Images size is not set. Use self.setImageSize(*size)")

        # new image size after registration of all images
        image_size = (self.img_width - max(diff_x),
                      self.img_height - max(diff_y))

        return (max(xs), max(ys)), image_size


    def channelParams(self, chname="Primary", color=None):
        f_cats, f_params = self.featureParams(chname)
        shift, size = self.registrationShift()
        params = {'strChannelId': color,
                  'channelRegistration': (self(
                    'ObjectDetection', '%s_channelregistration_x' %chname),
                                          self(
                    'ObjectDetection', '%s_channelregistration_y' %chname)),
                  'oZSliceOrProjection': self.zsliceParams(chname),
                  'new_image_size': size,
                  'registration_start': shift,
                  'fNormalizeMin': self('ObjectDetection', '%s_normalizemin' %chname),
                  'fNormalizeMax': self('ObjectDetection', '%s_normalizemax' %chname),
                  'lstFeatureCategories': f_cats,
                  'dctFeatureParameters': f_params}
        return params

    def channelRegions(self):
        """Return a dict of channel region pairs according to the classifier."""

        regions = OrderedDict()
        for ch_cls in self.CHANNEL_CLASSES:
            name = ch_cls.NAME
            if not ch_cls.is_virtual():
                region = self( \
                    "Classification", "%s_classification_regionname" %(name))

                # no plugins loaded
                if region not in (None, ""):
                    regions[name] = region
            else:
                regions2 = OrderedDict()
                for ch_cls2 in self.CHANNEL_CLASSES:
                    if ch_cls2.is_virtual():
                        continue
                    name2 =  ch_cls2.NAME
                    if self("Classification", "merge_%s" %name2):
                        regions2[name2] = self("Classification", "%s_%s_region" %(name, name2))
                if regions2:
                    regions[name] = regions2
        return regions
コード例 #4
0
class SettingsMapper(object):
    """Map parameters from a ConfigSettings instance to groups to fit
    the API"""

    CHANNEL_CLASSES = (PrimaryChannel, SecondaryChannel, TertiaryChannel)

    FEATURES = {
        'featurecategory_intensity': ['normbase', 'normbase2'],
        'featurecategory_haralick': ['haralick', 'haralick2'],
        'featurecategory_stat_geom': ['levelset'],
        'featurecategory_granugrey': ['granulometry'],
        'featurecategory_basicshape':
        ['roisize', 'circularity', 'irregularity', 'irregularity2', 'axes'],
        'featurecategory_convhull': ['convexhull'],
        'featurecategory_distance': ['distance'],
        'featurecategory_moments': ['moments']
    }

    def __init__(self, configfile):
        self.img_height = None
        self.img_width = None
        self.settings = ConfigSettings()
        self.settings.read(configfile)

    def __call__(self, section, param):
        return self.settings.get(section, param)

    def setImageSize(self, width, height):
        self.img_width = width
        self.img_height = height

    @property
    def img_size(self):
        return self.img_width, self.img_height

    def featureParams(self, ch_name="Primary"):
        f_categories = list()
        f_cat_params = dict()

        # unfortunateley some classes expect empty list and dict
        if ch_name.lower() in CH_VIRTUAL:
            return f_categories, f_cat_params

        for cat, feature in self.FEATURES.iteritems():
            featopt = '%s_%s' % (ch_name, cat)
            if self('FeatureExtraction', featopt):
                if "haralick" in cat:
                    try:
                        f_cat_params['haralick_categories'].extend(feature)
                    except KeyError:
                        assert isinstance(feature, list)
                        f_cat_params['haralick_categories'] = feature
                else:
                    f_categories += feature

        if f_cat_params.has_key("haralick_categories"):
            f_cat_params['haralick_distances'] = (1, 2, 4, 8)

        return f_categories, f_cat_params

    def zsliceParams(self, chname):
        self.settings.set_section('ObjectDetection')
        if self("ObjectDetection",
                "%s_%s" % (chname.lower(), 'zslice_selection')):
            par = self("ObjectDetection",
                       "%s_%s" % (chname.lower(), 'zslice_selection_slice'))
        elif self("ObjectDetection",
                  "%s_%s" % (chname.lower(), 'zslice_projection')):
            method = self(
                "ObjectDetection",
                "%s_%s" % (chname.lower(), 'zslice_projection_method'))
            begin = self("ObjectDetection",
                         "%s_%s" % (chname.lower(), 'zslice_projection_begin'))
            end = self("ObjectDetection",
                       "%s_%s" % (chname.lower(), 'zslice_projection_end'))
            step = self("ObjectDetection",
                        "%s_%s" % (chname.lower(), 'zslice_projection_step'))
            par = (method, begin, end, step)
        return par

    def registrationShift(self):
        xs = [0]
        ys = [0]

        for prefix in (SecondaryChannel.PREFIX, TertiaryChannel.PREFIX):
            if self('General', 'process_%s' % prefix):
                reg_x = self('ObjectDetection',
                             '%s_channelregistration_x' % prefix)
                reg_y = self('ObjectDetection',
                             '%s_channelregistration_y' % prefix)
                xs.append(reg_x)
                ys.append(reg_y)

        diff_x = []
        diff_y = []
        for i in range(len(xs)):
            for j in range(i, len(xs)):
                diff_x.append(abs(xs[i] - xs[j]))
                diff_y.append(abs(ys[i] - ys[j]))

        if self('General', 'crop_image'):
            y0 = self('General', 'crop_image_y0')
            y1 = self('General', 'crop_image_y1')
            x0 = self('General', 'crop_image_x0')
            x1 = self('General', 'crop_image_x1')

            self.img_width = x1 - x0
            self.img_height = y1 - y0

        if self.img_height is None or self.img_width is None:
            raise RuntimeError(
                "Images size is not set. Use self.setImageSize(*size)")

        # new image size after registration of all images
        image_size = (self.img_width - max(diff_x),
                      self.img_height - max(diff_y))

        return (max(xs), max(ys)), image_size

    def channelParams(self, chname="Primary", color=None):
        f_cats, f_params = self.featureParams(chname)
        shift, size = self.registrationShift()
        params = {
            'strChannelId':
            color,
            'channelRegistration':
            (self('ObjectDetection', '%s_channelregistration_x' % chname),
             self('ObjectDetection', '%s_channelregistration_y' % chname)),
            'oZSliceOrProjection':
            self.zsliceParams(chname),
            'new_image_size':
            size,
            'registration_start':
            shift,
            'fNormalizeMin':
            self('ObjectDetection', '%s_normalizemin' % chname),
            'fNormalizeMax':
            self('ObjectDetection', '%s_normalizemax' % chname),
            'lstFeatureCategories':
            f_cats,
            'dctFeatureParameters':
            f_params
        }
        return params

    def channelRegions(self):
        """Return a dict of channel region pairs according to the classifier."""

        regions = OrderedDict()
        for ch_cls in self.CHANNEL_CLASSES:
            name = ch_cls.NAME
            if not ch_cls.is_virtual():
                region = self( \
                    "Classification", "%s_classification_regionname" %(name))

                # no plugins loaded
                if region not in (None, ""):
                    regions[name] = region
            else:
                regions2 = OrderedDict()
                for ch_cls2 in self.CHANNEL_CLASSES:
                    if ch_cls2.is_virtual():
                        continue
                    name2 = ch_cls2.NAME
                    if self("Classification", "merge_%s" % name2):
                        regions2[name2] = self("Classification",
                                               "%s_%s_region" % (name, name2))
                if regions2:
                    regions[name] = regions2
        return regions
コード例 #5
0
ファイル: cecog_batch.py プロジェクト: PeterJackNaylor/cecog
    path_input = options.input
    path_output = options.output

    if path_input is not None:
        settings.set2('pathin', path_input)
        logger.info('Overwrite input path by %s' % path_input)
    else:
        path_input = settings.get2('pathin')
    if path_output is not None:
        settings.set2('pathout', path_output)
        logger.info('Overwrite output path by %s' % path_output)
    else:
        path_output = settings.get2('pathout')

    if multiple_plates is None:
        multiple_plates = settings.get(SECTION_NAME_GENERAL,
                                       'has_multiple_plates')
    else:
        logger.info('Overwrite has_multiple_plates by %s' % multiple_plates)

    imagecontainer = ImageContainer()
    if position_list is not None:
        positions = position_list.split(',')
        plates = set(np.array([el.split('___') for el in positions])[:, 0])
    else:
        plates = None

    imagecontainer.import_from_settings(settings, plates_restriction=plates)

    # FIXME: Could be more generally specified. SGE is setting the job item index via an environment variable
    if index is None:
        pass
コード例 #6
0
ファイル: batch.py プロジェクト: cmci/cecog
    path_output = options.output

    if path_input is not None:
        settings.set2('pathin', path_input)
        logger.info('Overwrite input path by %s' % path_input)
    else:
        path_input = settings.get2('pathin')
    if path_output is not None:
        settings.set2('pathout', path_output)
        logger.info('Overwrite output path by %s' % path_output)
    else:
        path_output = settings.get2('pathout')


    if multiple_plates is None:
        multiple_plates = settings.get(SECTION_NAME_GENERAL, 'has_multiple_plates')
    else:
        logger.info('Overwrite has_multiple_plates by %s' % multiple_plates)


    imagecontainer = ImageContainer()
    imagecontainer.import_from_settings(settings)

    # FIXME: Could be more generally specified. SGE is setting the job item index via an environment variable
    if index is None:
        pass
    elif index.isdigit():
        index = int(index)
    else:
        if index == ENV_INDEX_SGE:
            logger.info("Using SGE job item index: environment variable '%s'" % index)