1

I'm new in image analysis (with Python) and I would like to apply the richardson_lucy deconvolution (from skimage) on my data (CT scans). For this reason, I estimated the PSF in "number of voxels" by means of a specific software. Its value is roughly 6.73 voxels, but I don't know how to use it as a paramter in the function.

The function uses the PSF parameter as a ndarray, so I tried in this way:

from skimage import io
from pylab import array
img = io.imread ("Slice1.tif")
import skimage.restoration as rst
PSF = array (6.7)
img_dbl = rst.richardson_lucy (img, PSF, iterations=10)

It shows me this error: IndexError: too many indices for array

In CT scans, blurring between two different materials can be linked to a Gaussian PSF. If you have more tips for deblurring (maybe better than RL) just write them.

Can any one please help me.

Ajmal Sha
  • 906
  • 4
  • 17
  • 36
Sav
  • 142
  • 1
  • 17
  • Forget about PIL, you are supposed to open the image using `skimage.io.imread` instead. AFAIK PIL uses another image representation that that is not compatible with opencv or skimage. – Paulo Scardine Dec 01 '17 at 02:46
  • Thanks @PauloScardine, I changed it. However, it gives me the same error message. – Sav Dec 01 '17 at 03:00
  • Are you sure you are using a gray scale image? Try `img = color.rgb2gray(img)` before calling `richardson_lucy` – Paulo Scardine Dec 01 '17 at 03:05
  • The image is already in grayscale. I tried to convert it anyway, but the result is always the same. – Sav Dec 01 '17 at 03:26
  • Are you sure psf can be an unidimensional array? How about something like `np.ones((5, 5)) * 6.7` - running out of guesses. – Paulo Scardine Dec 01 '17 at 03:52
  • The function works but it returns an array made of "nan". – Sav Dec 01 '17 at 04:14
  • Aha, some progress - I don't know how you got that 6.7. What if you try with a value like the one from the example in the docs: `np.ones((5, 5)) / 25`? – Paulo Scardine Dec 01 '17 at 04:18
  • Already did it. It doesn't work in this way and there's nothing about it online that helps. I guess that the problem is the PSF parameter. I tried to see if there is a way to establish PSF using python but nothing came on internet. – Sav Dec 01 '17 at 04:29

1 Answers1

0

Have a similar problem and still researching it. In my case it didn't work if I didn't use np.uint8 as type. CT data should be 16 bit but only uses the first 12 bits (which are mapped to values between [-1024, 3096]. So I had to rescale my image data to [0-255] before getting anything than black or white out it.

If I understood that correctly, the sum of the PSF should always be 1. What I can guess from your question is that you assume the point spread function to be a gaussian with a meaningful (95% of values?) spread of 6.7 pixels. In that case you would have to model the PSF as a gaussian (that's what I came here for).

You can create one with the method described by @FuzzyDuck in this post.

PSF = gkern(5,2)

This would create a gaussian 5x5 kernel with sum 1 using the proposed method by @FuzzyDuck with a sigma of 2. Note that point spread functions could be applied several times so you have to experiment a little bit with the values (or use an algorithm to approximate that).

Pascal
  • 2,197
  • 3
  • 24
  • 34