def deconvolveLucy(self, image, continue_processing, signal_status_update):
# create the kernel
kernel = self.calculateKernel()
# flip the kernel for the convolution
kernel_flipped_vertically = np.flipud(kernel)
kernel_flipped = np.fliplr(kernel_flipped_vertically)
# set input image as initial guess
recent_reconstruction = np.copy(image)
# recursively calculate the maximum likelihood solution
for i in range(self.iterations):
if continue_processing[0] == False:
return "aborted"
percentage_finished = round(100. * float(i) / float(self.iterations))
status = "deconvolving: " + str(percentage_finished) + "%"
signal_status_update.emit(status)
# convolve the recent reconstruction with the kernel
convolved_recent_reconstruction = cv2.filter2D(recent_reconstruction,
-1,
kernel_flipped)
# calculate the correction array
correction = image / convolved_recent_reconstruction
# get infinite values (from divisions by zero)
infinite_values = np.invert(np.isfinite(correction))
#set infinite values to zero because according pixels are black
correction[infinite_values] = 0.
# convolve the correction
convolved_correction = cv2.filter2D(correction,
-1,
kernel)
recent_reconstruction *= convolved_correction
# print(recent_reconstruction)
return recent_reconstruction
## create a kernel image with a psf
# @todo: enable passing of psf
# @return kernel as numpy array
评论列表
文章目录