def test_vector_to_array(self): """ Test the vector to array coordinate system. """ for pos, val in zip(self.positions, self.values): self.array[pos] = val vector_index = array_to_vector_index(pos, self.array) self.assertEqual(self.array.flatten()[vector_index], val) array_index = vector_to_array_index(vector_index, self.array) self.assertEqual(tuple(array_index), pos)
def denoise(self): """ Method that computes the denoised image using NLM algorithm. Returns ------- denoise_array: array the denoised image. """ # Information message logger.info("Compute the denoised image using NLM algorithm.") # Allocate the denoised output image and the weight image denoise_array = numpy.zeros(self.shape, dtype=numpy.single) weights = numpy.zeros(self.shape, dtype=numpy.single) # Go through all the voxels and compute the denoise image logger.info("Running denoising...") for vector_index in range(self.to_denoise_array.size): # Convert vector index to array index index = vector_to_array_index(vector_index, self.to_denoise_array) # Falst blockwise non overlap speed up if (self.blockwise_strategy != "fastblockwise" or (numpy.mod(index, self.half_patch_size + 1) == 0).all()): # Check if have to compute this voxel if self.mask_array[tuple(index)] > 0: # Compute the denoised patch patch, weight = self._get_denoised_patch(index) # Apply the denoised patch self._apply_patch(index, patch, denoise_array, weights, weight=1.) # Apply the weightings to the denoised image weights[numpy.where(weights == 0)] = 1. denoise_array /= weights return denoise_array
def test_speed(self): """ Test the patch creation speed. """ for vector_index in range(self.array.size): index = vector_to_array_index(vector_index, self.array) patch = c_get_patch(index, self.array, self.full_patch_size)