Пример #1
0
    def replace_labels(self,
                       data_nr,
                       blocks,
                       block_slices,
                       delete_old_blocks=True):
        """Replaces the labels and their block slices of the dataset.

        :param data_nr: number of dataset
        :param blocks: label blocks
        :param block_slices: block slices
        :param delete_old_blocks: whether the old blocks in the project file shall be deleted
        """
        if len(blocks) != len(block_slices):
            raise Exception(
                "The number of blocks and block slices must be the same.")
        if not delete_old_blocks:
            if len(blocks) != self._label_block_count(data_nr):
                raise Exception("Wrong number of label blocks to be inserted.")

        if delete_old_blocks:
            self.remove_labels(data_nr)

        proj = h5py.File(self.project_filename, "r+")
        for i in range(len(blocks)):
            vigra.writeHDF5(blocks[i], self.project_filename,
                            const.label_blocks(data_nr, i))
            h5_blocks = eval_h5(proj, const.label_blocks_list(data_nr, i))
            h5_blocks.attrs['blockSlice'] = block_slices[i]
        proj.close()
Пример #2
0
 def remove_labels(self, data_nr=None):
     """Remove the label blocks of the given dataset from the project.
     """
     if data_nr is None:
         for i in xrange(self.data_count):
             self.remove_labels(i)
     else:
         proj = h5py.File(self.project_filename, "r+")
         for i in range(self._label_block_count(data_nr)):
             del_from_h5(proj, const.label_blocks_list(data_nr, i))
         proj.close()
Пример #3
0
 def remove_labels(self, data_nr=None):
     """Remove the label blocks of the given dataset from the project.
     """
     if data_nr is None:
         for i in xrange(self.data_count):
             self.remove_labels(i)
     else:
         proj = h5py.File(self.project_filename, "r+")
         for i in range(self._label_block_count(data_nr)):
             del_from_h5(proj, const.label_blocks_list(data_nr, i))
         proj.close()
Пример #4
0
    def get_labels(self, data_nr):
        """Returns the labels and their block slices of the dataset.

        :param data_nr: number of dataset
        :return: labels and blockslices of the dataset
        :rtype: tuple
        """
        # Read the label blocks.
        block_count = self._label_block_count(data_nr)
        blocks = [vigra.readHDF5(self.project_filename, const.label_blocks(data_nr, i))
                  for i in range(block_count)]

        # Read the block slices.
        proj = h5py.File(self.project_filename, "r")
        block_slices = [eval_h5(proj, const.label_blocks_list(data_nr, i)).attrs['blockSlice']
                        for i in range(block_count)]
        proj.close()
        return blocks, block_slices
Пример #5
0
    def replace_labels(self, data_nr, blocks, block_slices, delete_old_blocks=True):
        """Replaces the labels and their block slices of the dataset.

        :param data_nr: number of dataset
        :param blocks: label blocks
        :param block_slices: block slices
        :param delete_old_blocks: whether the old blocks in the project file shall be deleted
        """
        if len(blocks) != len(block_slices):
            raise Exception("The number of blocks and block slices must be the same.")
        if not delete_old_blocks:
            if len(blocks) != self._label_block_count(data_nr):
                raise Exception("Wrong number of label blocks to be inserted.")

        if delete_old_blocks:
            self.remove_labels(data_nr)

        proj = h5py.File(self.project_filename, "r+")
        for i in range(len(blocks)):
            vigra.writeHDF5(blocks[i], self.project_filename, const.label_blocks(data_nr, i))
            h5_blocks = eval_h5(proj, const.label_blocks_list(data_nr, i))
            h5_blocks.attrs['blockSlice'] = block_slices[i]
        proj.close()
Пример #6
0
    def get_labels(self, data_nr):
        """Returns the labels and their block slices of the dataset.

        :param data_nr: number of dataset
        :return: labels and blockslices of the dataset
        :rtype: tuple
        """
        # Read the label blocks.
        block_count = self._label_block_count(data_nr)
        blocks = [
            vigra.readHDF5(self.project_filename,
                           const.label_blocks(data_nr, i))
            for i in range(block_count)
        ]

        # Read the block slices.
        proj = h5py.File(self.project_filename, "r")
        block_slices = [
            eval_h5(proj, const.label_blocks_list(data_nr,
                                                  i)).attrs['blockSlice']
            for i in range(block_count)
        ]
        proj.close()
        return blocks, block_slices