示例#1
0
    def apply_zselection(self):
        if type(self.oZSliceOrProjection) == types.TupleType:
            method, zbegin, zend, zstep = self.oZSliceOrProjection
            images = [img.image for img in self._zslices][(zbegin-1):zend:zstep]
            # single images don't carry the dtype
            dtype = img.format

            if method == "maximum":
                method_const = ccore.ProjectionType.MaxProjection
            elif method == "minimum":
                method_const = ccore.ProjectionType.MinProjection
            elif method == "average":
                method_const = ccore.ProjectionType.MeanProjection

            self.logger.debug("* applying %s Z-Projection to stack of %d images..."
                              %(method, len(images)))
            imgprj = numpy.zeros((images[0].height, images[0].width), dtype=dtype)
            imgprj = ccore.numpy_to_image(numpy.zeros((images[0].height, images[0].width), dtype=dtype), copy=True)
            ccore.zproject(imgprj, images, method_const)

            # overwrite the first MetaImage found with the projected image data
            meta_image = self._zslices[0]
            meta_image.set_image(imgprj)
        else:
            self.oZSliceOrProjection = int(self.oZSliceOrProjection)
            self.logger.debug("* selecting z-slice %d..." % self.oZSliceOrProjection)
            try:
                meta_image = self._zslices[self.oZSliceOrProjection-1]
            except IndexError:
                raise IndexError("Invalid z-slice selection for channel %s"
                                 %self.NAME)

        self.meta_image = copy.copy(meta_image)
示例#2
0
    def _run(self, meta_image):
        image = meta_image.image

        img_prefiltered = self.prefilter(image)
        
        img_bin1 = self.threshold(img_prefiltered, self.params['latwindowsize'], self.params['latlimit'])

        if self.params['holefilling']:
            ccore.fill_holes(img_bin1, False)

        if self.params['lat2']:
            img_bin2 = self.threshold(img_prefiltered, self.params['latwindowsize2'],
                                      self.params['latlimit2'])

            # replacement for not working ccore.projectImage
            img_bin = numpy.zeros((img_bin2.height, img_bin2.width),
                                 dtype=meta_image.format)
            img_bin = ccore.numpy_to_image(img_bin, copy=True)
            ccore.zproject(img_bin, [img_bin1, img_bin2], ccore.ProjectionType.MaxProjection)
        else:
            img_bin = img_bin1

        if self.params['watershed_distance']:
            img_bin = self.correct_segmetation(img_prefiltered, img_bin, 
                                               self.params['watershed_dynamic'],
                                               self.params['watershed_used_distance'])
            
#        if self.params['shapewatershed']:
#            img_bin = self.correct_segmetation(img_prefiltered, img_bin,
#                                               self.params['latwindowsize'],
#                                               self.params['shapewatershed_gausssize'],
#                                               self.params['shapewatershed_maximasize'],
#                                               self.params['shapewatershed_minmergesize'],
#                                               kind='shape')
#        if self.params['intensitywatershed']:
#            img_bin = self.correct_segmetation(img_prefiltered, img_bin,
#                                               self.params['latwindowsize'],
#                                               self.params['intensitywatershed_gausssize'],
#                                               self.params['intensitywatershed_maximasize'],
#                                               self.params['intensitywatershed_minmergesize'],
#                                               kind='intensity')

        container = ccore.ImageMaskContainer(image, img_bin, self.params['removeborderobjects'])
 
        # calculate offset: mean on the background region, as given by the segmentation result
        # no locality: simply a global mean on the image. 
        np_image = image.toArray(True)
        np_img_bin = img_bin.toArray(True)
        offset = np_image[np_img_bin==0].mean()
        
        self.postprocessing(container, self.params['postprocessing'],
                            (self.params['postprocessing_roisize_min'], self.params['postprocessing_roisize_max']),
                            (self.params['postprocessing_intensity_min'], self.params['postprocessing_intensity_max']),
                            offset=offset)

        return container
示例#3
0
    def _run(self, meta_image):
        image = meta_image.image

        img_prefiltered = self.prefilter(image)
        img_bin1 = self.threshold(img_prefiltered, self.params['latwindowsize'], self.params['latlimit'])

        if self.params['holefilling']:
            ccore.fill_holes(img_bin1, False)

        if self.params['lat2']:
            img_bin2 = self.threshold(img_prefiltered, self.params['latwindowsize2'],
                                      self.params['latlimit2'])

            # replacement for not working ccore.projectImage
            img_bin = numpy.zeros((img_bin2.height, img_bin2.width),
                                 dtype=meta_image.format)
            img_bin = ccore.numpy_to_image(img_bin, copy=True)
            ccore.zproject(img_bin, [img_bin1, img_bin2], ccore.ProjectionType.MaxProjection)
        else:
            img_bin = img_bin1


        if self.params['shapewatershed']:
            img_bin = self.correct_segmetation(img_prefiltered, img_bin,
                                               self.params['latwindowsize'],
                                               self.params['shapewatershed_gausssize'],
                                               self.params['shapewatershed_maximasize'],
                                               self.params['shapewatershed_minmergesize'],
                                               kind='shape')
        if self.params['intensitywatershed']:
            img_bin = self.correct_segmetation(img_prefiltered, img_bin,
                                               self.params['latwindowsize'],
                                               self.params['intensitywatershed_gausssize'],
                                               self.params['intensitywatershed_maximasize'],
                                               self.params['intensitywatershed_minmergesize'],
                                               kind='intensity')

        container = ccore.ImageMaskContainer(image, img_bin, self.params['removeborderobjects'])

        self.postprocessing(container, self.params['postprocessing'],
                            (self.params['postprocessing_roisize_min'], self.params['postprocessing_roisize_max']),
                            (self.params['postprocessing_intensity_min'], self.params['postprocessing_intensity_max']))

        return container
示例#4
0
    def apply_zselection(self):
        if type(self.oZSliceOrProjection) == types.TupleType:
            method, zbegin, zend, zstep = self.oZSliceOrProjection
            images = [img.image
                      for img in self._zslices][(zbegin - 1):zend:zstep]
            # single images don't carry the dtype
            dtype = img.format

            if method == "maximum":
                method_const = ccore.ProjectionType.MaxProjection
            elif method == "minimum":
                method_const = ccore.ProjectionType.MinProjection
            elif method == "average":
                method_const = ccore.ProjectionType.MeanProjection

            self.logger.debug(
                "* applying %s Z-Projection to stack of %d images..." %
                (method, len(images)))
            imgprj = numpy.zeros((images[0].height, images[0].width),
                                 dtype=dtype)
            imgprj = ccore.numpy_to_image(numpy.zeros(
                (images[0].height, images[0].width), dtype=dtype),
                                          copy=True)
            ccore.zproject(imgprj, images, method_const)

            # overwrite the first MetaImage found with the projected image data
            meta_image = self._zslices[0]
            meta_image.set_image(imgprj)
        else:
            self.oZSliceOrProjection = int(self.oZSliceOrProjection)
            self.logger.debug("* selecting z-slice %d..." %
                              self.oZSliceOrProjection)
            try:
                meta_image = self._zslices[self.oZSliceOrProjection - 1]
            except IndexError:
                raise IndexError("Invalid z-slice selection for channel %s" %
                                 self.NAME)

        self.meta_image = copy.copy(meta_image)