Ejemplo n.º 1
0
    def crop(self, tmpcrinfo):
        """
        Function makes crop of 3d data and seeds and stores it in crinfo.

        tmpcrinfo: temporary crop information

        """
        # print ('sedds ', str(self.seeds.shape), ' se ',
        #       str(self.segmentation.shape), ' d3d ', str(self.data3d.shape))
        self.data3d = qmisc.crop(self.data3d, tmpcrinfo)
# No, size of seeds should be same as data3d
        if self.seeds is not None:
            self.seeds = qmisc.crop(self.seeds, tmpcrinfo)

        if self.segmentation is not None:
            self.segmentation = qmisc.crop(self.segmentation, tmpcrinfo)

        self.crinfo = qmisc.combinecrinfo(self.crinfo, tmpcrinfo)
        logger.debug("crinfo " + str(self.crinfo))
Ejemplo n.º 2
0
    def test_multiple_crop_and_uncrop(self):
        """
        test combination of multiple crop
        """

        shape = [10, 10, 5]
        img_in = np.random.random(shape)

        crinfo1 = [[2, 8], [3, 9], [2, 5]]
        crinfo2 = [[2, 5], [1, 4], [1, 2]]

        img_cropped = qmisc.crop(img_in, crinfo1)
        img_cropped = qmisc.crop(img_cropped, crinfo2)

        crinfo_combined = qmisc.combinecrinfo(crinfo1, crinfo2)

        img_uncropped = qmisc.uncrop(img_cropped, crinfo_combined, shape)

        self.assertTrue(img_uncropped[4, 4, 3] == img_in[4, 4, 3])
Ejemplo n.º 3
0
    def _interactivity_end(self, igc):
        logger.debug('_interactivity_end')
        #print "sh3", self.data3d.shape

#        import pdb; pdb.set_trace()
#        scipy.ndimage.zoom(
#                self.segmentation,
#                1.0 / self.zoom,
#                output=segm_orig_scale,
#                mode='nearest',
#                order=0
#                )
        segm_orig_scale = scipy.ndimage.zoom(
            self.segmentation,
            1.0 / self.zoom,
            mode='nearest',
            order=0
        ).astype(np.int8)
        seeds = scipy.ndimage.zoom(
            igc.seeds,
            1.0 / self.zoom,
            mode='nearest',
            order=0
        )

        #print  np.sum(self.segmentation)*np.prod(self.voxelsize_mm)

# @TODO odstranit hack pro oříznutí na stejnou velikost
# v podstatě je to vyřešeno, ale nechalo by se to dělat elegantněji v zoom
# tam je bohužel patrně bug
        shp = [
            np.min([segm_orig_scale.shape[0], self.data3d.shape[0]]),
            np.min([segm_orig_scale.shape[1], self.data3d.shape[1]]),
            np.min([segm_orig_scale.shape[2], self.data3d.shape[2]]),
        ]
        #self.data3d = self.data3d[0:shp[0], 0:shp[1], 0:shp[2]]

        self.segmentation = np.zeros(self.data3d.shape, dtype=np.int8)
        self.segmentation[
            0:shp[0],
            0:shp[1],
            0:shp[2]] = segm_orig_scale[0:shp[0], 0:shp[1], 0:shp[2]]

        del segm_orig_scale

        self.iparams['seeds'] = np.zeros(self.data3d.shape, dtype=np.int8)
        self.iparams['seeds'][
            0:shp[0],
            0:shp[1],
            0:shp[2]] = seeds[0:shp[0], 0:shp[1], 0:shp[2]]
#
        if self.segmentation_smoothing:
            self.segm_smoothing(self.smoothing_mm)

        #print 'crinfo: ', self.crinfo
        #print 'autocrop', self.autocrop
        if self.autocrop is True:
            #print
            #import pdb; pdb.set_trace()

            tmpcrinfo = self._crinfo_from_specific_data(
                self.segmentation,
                self.autocrop_margin)
            self.segmentation = self._crop(self.segmentation, tmpcrinfo)
            self.data3d = self._crop(self.data3d, tmpcrinfo)

            self.crinfo = qmisc.combinecrinfo(self.crinfo, tmpcrinfo)

        if self.texture_analysis not in (None, False):
            import texture_analysis
            # doplnit nějaký kód, parametry atd
            #self.orig_scale_segmentation =
            # texture_analysis.segmentation(self.data3d,
            # self.orig_scale_segmentation, params = self.texture_analysis)
            self.segmentation = texture_analysis.segmentation(
                self.data3d,
                self.segmentation,
                self.voxelsize_mm
            )

        # set label number
        self.segmentation[self.segmentation == 1] = self.output_label
#
        self.processing_time = time.time() - self.time_start