Open materialvision opened 10 months ago
Nice! My general thought is I want to keep things simple and not intrude too much on areas well covered by existing tools, but I think this makes sense if we don't go too far in just reproducing Imppg. I'll take a look.
Yes, I agree to keep things simple. I suspect most people will do their own sharpening in other software first. But for me, I am primarily doing time-lapses with 1000s of images so anything that can be automated in one process is good:-) It was surprising to me how simple the function to do l-r convolution in python was! I am no programming expert, but I found the basic one in an answer on stack-overflow and modified it abit.
Makes sense. I took a quick look. I noticed for my image, it ended up with an all-black result, apparently due to division by zero. Adding this in the loop seemed to fix it:
convolved = convolve(estimate, psf, mode='same')
convolved = convolved.clip(min=0.00000001)
relative_blur = image / convolved
Though looking a bit further, I found this, which seemed to be an existing off-the-shelf implementation, though I haven't looked deeper to see about how one tunes it. I guess the "np.ones((5, 5)) / 25" bit is used as a starting point and doesn't need to be a gaussian? I just copied that from an example and haven't looked deeper to see what the implication is.
from skimage import restoration def lucy_richardson2(image, psf_sigma, iterations): psf = np.ones((5, 5)) / 25 return restoration.richardson_lucy(image, psf, num_iter=iterations)
Before integrating, I'd want to think how best to handle it in the interactive window. It's so slow, it can't be handled the same way as the other operations. Which makes me wonder if there is a faster implementation lying around somewhere, but also how to handle such non-interactive bits. It's similar to the alignment button which also takes a minute to run.
Ah! Took another look, and I think it makes more sense to just use your psf generation, like:
def lucy_richardson2(image, psf_sigma, iterations):
# Generate an initial PSF
psf_size = 21 # Adjust this size as needed 21
sigma = psf_sigma # Adjust standard deviation as needed 2.5
psf = generate_psf(psf_size, sigma)
return restoration.richardson_lucy(image, psf, num_iter=iterations)
Yes I suspect that a faster implementation would involve some more compiled language like c++ - And I also noticed that the image gets a bit darker when it is applied, so one could make some offset in the gamma maybe to counter that.
The way I did it here was just to take it out of the "update" loop, and apply only once as a first step, thinking that when it is this simple like an on-off button it doesn't matter that it is a bit slow. If the next step is to add a slider for the sigma value of the PSF for example (since that seems to be the one adjustable parameter that makes the biggest difference. Imppg also have the number of iterations user adjustable so that could be another slider possibly), then it would have to include a kind of "update values" button to do the deconvolute again. It would work but not be as fast as imppg and others where you see the result much more instant.
Hi, I tried to add a simple deconvolution to your great script. I don´t know if it is interesting but you can have a look. For me it is useful with a simple all-in-one (after stacking...) solution to run solar images through. It probably needs some debugging, I have only tested in python on mac. Also one can add a slider for the Sigma value and the size perhaps to give more control over the deconvolution.