Пример #1
0
    def prepare_raw_image(self, channel):
        self.create_nc4()

        desc = '[P %s, T %05d, C %s]' % (self.P, self._iCurrentT,
                                         channel.strChannelId)
        if self._create_nc or self._reuse_nc:
            grp = self._dataset.groups[self.NC_GROUP_RAW]
            var = grp.variables[channel.strChannelId]
            frame_idx = self._frames_to_idx[self._iCurrentT]
            
            if len(var.valid.shape) == 0:
                frame_valid = var.valid
            else:
                frame_valid = var.valid[frame_idx]
                    
        if self._reuse_nc and frame_valid:
            coordinate = Coordinate(position=self.P, time=self._iCurrentT,
                                    channel=channel.strChannelId, zslice=1)
            meta_image = MetaImage(image_container=None, coordinate=coordinate)

            img = ccore.numpy_to_image(var[frame_idx], copy=True)
            meta_image.set_image(img)
            meta_image.set_raw_image(img)
            channel.meta_image = meta_image
            self._logger.debug('Raw image %s loaded from nc4 file.' % desc)
        else:
            channel.apply_zselection()
            channel.normalize_image()
            channel.apply_registration()
            if self._create_nc:
                img = channel.meta_image.image
                grp = self._dataset.groups[self.NC_GROUP_RAW]
                var = grp.variables[channel.strChannelId]
                var[frame_idx] = img.toArray(copy=False)
                self.nc_valid_set(var, frame_idx, 1)
                self._logger.debug('Raw image %s written to nc4 file.' % desc)

        if self._hdf5_create and self._hdf5_include_raw_images:
            meta = self._meta_data
            w = meta.real_image_width
            h = meta.real_image_height
            f = self._hdf5_file
            if 'images' in f:
                images = f['images']
            else:
                images = f.create_dataset('pre_images', (meta.dim_c, meta.dim_t, meta.dim_z, w, h),
                                          'uint8', compression='szip', chunks=(1,1,meta.dim_z,w,h))
                dt = h5py.special_dtype(vlen=str)
                channels = f.create_dataset('channel_names', (meta.dim_c,), dt)
                for idx in range(meta.dim_c):
                    channels[idx] = self._idx_to_channels[idx]

            frame_idx = self._frames_to_idx[self._iCurrentT]
            channel_idx = self._channels_to_idx[channel.strChannelId]
            img = channel.meta_image.image
            array = img.toArray(copy=False)
            print array.shape, (meta.dim_c, meta.dim_t, meta.dim_z, w, h), frame_idx, channel_idx
            images[channel_idx, frame_idx, 0] = array
Пример #2
0
Файл: core.py Проект: jni/cecog
 def _setup_cropping(self):
     crop = self.settings.get('General', 'crop_image')
     x0 = self.settings.get('General', 'crop_image_x0')
     y0 = self.settings.get('General', 'crop_image_y0')
     x1 = self.settings.get('General', 'crop_image_x1')
     y1 = self.settings.get('General', 'crop_image_y1')
     if crop:
         MetaImage.enable_cropping(x0, y0, x1-x0, y1-y0)
         self.logger.info("cropping enabled with %d %d %d %d"
                          % (x0, y0, x1-x0, y1-y0))
     else:
         MetaImage.disable_cropping()
         self.logger.info("cropping disabled")
Пример #3
0
    def __init__(self, mapper, images):
        super(ImageProcessor, self).__init__()
        self.mapper = mapper
        self._channels = OrderedDict()

        self.metaimages = dict()
        for name, image in images.iteritems():
            metaimage = MetaImage()
            metaimage.set_image(ccore.readImage(image))
            self.metaimages[name] = [metaimage]

        self.mapper.setImageSize(metaimage.width, metaimage.height)
        self._setupChannels(images)
Пример #4
0
    def __init__(self, mapper, images):
        super(ImageProcessor, self).__init__()
        self.mapper = mapper
        self._channels = OrderedDict()

        self.metaimages = dict()
        for name, image in images.iteritems():
            metaimage = MetaImage()
            metaimage.set_image(ccore.readImage(image))
            self.metaimages[name] = [metaimage]

        self.mapper.setImageSize(metaimage.width, metaimage.height)
        self._setupChannels(images)
Пример #5
0
 def _setup_cropping(self):
     crop = self.settings.get('General', 'crop_image')
     x0 = self.settings.get('General', 'crop_image_x0')
     y0 = self.settings.get('General', 'crop_image_y0')
     x1 = self.settings.get('General', 'crop_image_x1')
     y1 = self.settings.get('General', 'crop_image_y1')
     if crop:
         MetaImage.enable_cropping(x0, y0, x1 - x0, y1 - y0)
         self.logger.info("cropping enabled with %d %d %d %d" %
                          (x0, y0, x1 - x0, y1 - y0))
     else:
         MetaImage.disable_cropping()
         self.logger.info("cropping disabled")
Пример #6
0
    def normalize_image(self, plate_id=None):

        img_in = self.meta_image.image
        if self.bFlatfieldCorrection:
            self.logger.debug("* using flat field correction with image from %s"
                              % self.strBackgroundImagePath)
            imgBackground = self._load_flatfield_correction_image(plate_id)

            crop_coordinated = MetaImage.get_crop_coordinates()
            if crop_coordinated is not None:
                self.logger.debug("* applying cropping to background image")
                imgBackground = ccore.subImage(imgBackground,
                                               ccore.Diff2D(crop_coordinated[0],
                                                            crop_coordinated[1]),
                                               ccore.Diff2D(crop_coordinated[2],
                                                            crop_coordinated[3]))

            img_in = ccore.flatfieldCorrection(img_in, imgBackground, 0.0, True)
            img_out = ccore.linearTransform2(img_in, self.fNormalizeMin,
                                             self.fNormalizeMax, 0, 255, 0, 255)
        else:
            self.logger.debug("* not using flat field correction")
            if type(img_in) == ccore.UInt16Image:
                img_out = ccore.linearTransform3(img_in, int(self.fNormalizeMin),
                                                 int(self.fNormalizeMax),
                                                 0, 255, 0, 255)
            elif type(img_in) == ccore.Image:
                img_out = ccore.linearTransform2(img_in, int(self.fNormalizeMin),
                                                 int(self.fNormalizeMax),
                                                 0, 255, 0, 255)

            else:
                img_out = img_in

        self.meta_image.set_image(img_out)
Пример #7
0
    def normalize_image(self, plate_id=None):
        try:
            import pydevd
            pydevd.connected = True
            pydevd.settrace(suspend=False)
            print 'Thread enabled interactive eclipse debuging...'
        except:
            pass
        img_in = self.meta_image.image
        if self.bFlatfieldCorrection:
            self.logger.debug(
                "* using flat field correction with image from %s" %
                self.strBackgroundImagePath)
            imgBackground = self._load_flatfield_correction_image(plate_id)

            crop_coordinated = MetaImage.get_crop_coordinates()
            if crop_coordinated is not None:
                self.logger.debug("* applying cropping to background image")
                imgBackground = ccore.subImage(
                    imgBackground,
                    ccore.Diff2D(crop_coordinated[0], crop_coordinated[1]),
                    ccore.Diff2D(crop_coordinated[2], crop_coordinated[3]))

            img_in = ccore.flatfieldCorrection(img_in, imgBackground, 0.0,
                                               True)
            img_out = ccore.linearTransform2(img_in, self.fNormalizeMin,
                                             self.fNormalizeMax, 0, 255, 0,
                                             255)
        else:
            self.logger.debug("* not using flat field correction")
            if type(img_in) == ccore.UInt16Image:
                img_out = ccore.linearTransform3(img_in,
                                                 int(self.fNormalizeMin),
                                                 int(self.fNormalizeMax), 0,
                                                 255, 0, 255)
            elif type(img_in) == ccore.Image:
                img_out = ccore.linearTransform2(img_in,
                                                 int(self.fNormalizeMin),
                                                 int(self.fNormalizeMax), 0,
                                                 255, 0, 255)

            else:
                img_out = img_in

        self.meta_image.set_image(img_out)
Пример #8
0
    def normalize_image(self, plate_id=None):
        try:
            import pydevd
            pydevd.connected = True
            pydevd.settrace(suspend=False)
            print 'Thread enabled interactive eclipse debuging...'
        except:
            pass
        img_in = self.meta_image.image
        if self.bFlatfieldCorrection:
            self.logger.debug("* using flat field correction with image from %s"
                              % self.strBackgroundImagePath)
            imgBackground = self._load_flatfield_correction_image(plate_id)

            crop_coordinated = MetaImage.get_crop_coordinates()
            if crop_coordinated is not None:
                self.logger.debug("* applying cropping to background image")
                imgBackground = ccore.subImage(imgBackground,
                                               ccore.Diff2D(crop_coordinated[0],
                                                            crop_coordinated[1]),
                                               ccore.Diff2D(crop_coordinated[2],
                                                            crop_coordinated[3]))

            img_in = ccore.flatfieldCorrection(img_in, imgBackground, 0.0, True)
            img_out = ccore.linearTransform2(img_in, self.fNormalizeMin,
                                             self.fNormalizeMax, 0, 255, 0, 255)
        else:
            self.logger.debug("* not using flat field correction")
            if type(img_in) == ccore.UInt16Image:
                img_out = ccore.linearTransform3(img_in, int(self.fNormalizeMin),
                                                 int(self.fNormalizeMax),
                                                 0, 255, 0, 255)
            elif type(img_in) == ccore.Image:
                img_out = ccore.linearTransform2(img_in, int(self.fNormalizeMin),
                                                 int(self.fNormalizeMax),
                                                 0, 255, 0, 255)

            else:
                img_out = img_in

        self.meta_image.set_image(img_out)
Пример #9
0
    def normalize_image(self, plate_id=None):

        img_in = self.meta_image.image
        if self.bFlatfieldCorrection:
            self.logger.debug(
                "* using flat field correction with image from %s" %
                self.strBackgroundImagePath)
            imgBackground = self._load_flatfield_correction_image(plate_id)

            crop_coordinated = MetaImage.get_crop_coordinates()
            if crop_coordinated is not None:
                self.logger.debug("* applying cropping to background image")
                imgBackground = ccore.subImage(
                    imgBackground,
                    ccore.Diff2D(crop_coordinated[0], crop_coordinated[1]),
                    ccore.Diff2D(crop_coordinated[2], crop_coordinated[3]))

            img_in = ccore.flatfieldCorrection(img_in, imgBackground, 0.0,
                                               True)
            img_out = ccore.linearTransform2(img_in, self.fNormalizeMin,
                                             self.fNormalizeMax, 0, 255, 0,
                                             255)
        else:
            self.logger.debug("* not using flat field correction")
            if type(img_in) == ccore.UInt16Image:
                img_out = ccore.linearTransform3(img_in,
                                                 int(self.fNormalizeMin),
                                                 int(self.fNormalizeMax), 0,
                                                 255, 0, 255)
            elif type(img_in) == ccore.Image:
                img_out = ccore.linearTransform2(img_in,
                                                 int(self.fNormalizeMin),
                                                 int(self.fNormalizeMax), 0,
                                                 255, 0, 255)

            else:
                img_out = img_in

        self.meta_image.set_image(img_out)