Main Menu
Home
Software
1D Deconvolution
2D Deconvolution
3D Deconvolution
User forum
About us
External links

Deconvolve .Net
User's Forum

DR: Using the PSF (02/08/2010 08:55) 
Hi,
I have been using the demo file DemoBlind.zip to deconvolve an image that is blurred in one direction.
I initially used Mathematica to convert between fit format and tif or anything that Corel Photopaint would produce. This seemed to give problems with the file header, so I eventually found and started using xtox.exe. I ended up with a 252 by 252 pixel file that would deconvolve, and started with a totally blank psf.
After running the program DeconBMI and inspecting the resulting doubles file I found how to set the right range in BiaQIm using the stats and range functions. It appears that it is all below the 0.003 range, numerically.
In addition, I made a small Mathematica routine to view the array in terms of a 3d plot.
This binary doubles psf file had substantial nonzero hills well away from the central linear smear, which I imagine is the part I want. I found how to edit the doubles file using masks in the BiaQIm viewer, and after cleaning it up saved to disk.
My problem now is how to apply it to the image. Running it as the initial psf in DeconBMI results in the unwanted parts returning and the image isn't cleaned up. Is there an easy way to constrain which parts of the psf may be changed by the deconvolution software, and which not? Working with BiaQIm there is no viewer present to see how the psf is developing. How do I activate it?
I tried to use BiaQIm to do a single deconvolve using the psf that I had found, yet this does not seem to work. It runs, but the final image after 1, 10, or 100 iterations is obviously not deconvolved as the psf specifies. It develops a lot of small scale noise, and I can't find where it saves the psf it is using.
Convolve.exe ought to be usable, but there is no option to set the psf as the file to deconvolve with instead of worsening the image by convolving, so I left this option at present. Finding the reciprocal might be an option, but I would need to do this in the frequency domain.
I would appreciate any help you could give. I attach the settings used in BiaQIm and the blurred image of some railings from the photo, as well as the doubles file with the psf after my edit to remove distant hills.
(I have some more photos with considerably long streaks due to camera shake, and it would be nice to know how to best get the psf to follow a linear curved path, perhaps by tracing from the image?)
Further general comment, I am quite familiar with Mathematica and have used it to recognize letters using deconvolution. I am somewhat ignorant about the actual mathematical methods used to update the psf for the various methods. It would be nice to have a summary if possible.
Also, I have done some C++ programming to solve the biharmonic equation for a plate, tridiagonal matrix inversion etc. There is no doubt that you are using the right language for your programs, in terms of speed, but I actually find that for converting ideas to working code, Mathematica is very good because it is such an abstract language. So I was thinking that for education about the principles it might be nice to convert one of the algorithms to this language, even if it runs a bit slow. Clearly there is a lot more going on in your routines, beyond this.
Also curious about the lack of user discussion.

Dr Tadrous: Using the PSF (07/08/2010 11:16) 
Dear DR,
Thank you for your interest in the software and your queries. I will try to answer them point by point. I would be grateful if you can give me feedback as to whether this reply was helpful. Your comments are in grey:
file header, so I eventually found and started using xtox.exe. I ended up with a 252 by 252 pixel file that would deconvolve, and started with a totally blank psf.
It is not a good idea to start with a totally blank PSF. If 'totally blank' means all zeros then there is no power in the Fourier domain for the algorithm to form the solution our of except that generated by roundoff errors (so it might work but be slow in converging or give spurious results of the roundoffs have some periodic structure). If 'totally blank' means all uniform nonzero valued pixels then this can create a strong prior distribution int he Fourier domain (the frequency spectrum of a pulse) and this could dominate the solution for many iterations and it may not converge properly. For the demo I use such a uniform PSF and, as it happens in that particular case, it works  but it doesn't always. A good generic starting point for a blinf PSF is either a good estimate of the true PSF (if you have one) or a plane of random noise. (Avoid using a single pixel Dirac pulse  this is the trivial solution). As an aside, why did you chose 252x252? The Fourier transforms in this case will all be of the slow type. If you use 256x256 the speed will greatly increas as FFTs will be deployed.
cleaned up. Is there an easy way to constrain which parts of the psf may be changed by the deconvolution software, and which not?
Yes. For DeconBMI you need to supply two template deconvolution dettings files. In either one you can set the weghts border or supply a custom weights file. So, in your case you want to set the weights file (or weights border) in the PSF settings file (called DCSetPSF.txt in the demo). The two settings you can use fo this are:
[Weights____file] NONE
[BlankWghtBorder] YES 8 8 8
The options given here are the ones used in the demo. You can change NONE to the name of a raw doubles file that has pixel value 0.0 where you want no change and pixel value 1.0 where you want full change. When making such a file you may want to 'smooth the edges' i.e. avoid abrupt transitions from 0.0 to 1.0  but it may not be important. If you just want to ensure that no change occurs at the periphery for a certain number of pixels then it is easier to just use the [BlankWghtBorder] setting and change 8 8 8 to whatever pixels thickness you wnat the nonchanging border to be (the third digit is only use for 3D datasets). If you use this please ensure that the prior PSF has zero pixel values in the regions where your mask is zero. This enables the flux to be conserved (otherwise the solution may fail).
I tried to use BiaQIm to do a single deconvolve using the psf that I had found, yet this does not seem to work. It runs, but the final image after 1, 10, or 100 iterations is obviously not deconvolved as the psf specifies. It develops a lot of small scale noise, and I can't find where it saves the psf it is using.
I am not sure what happened in your case but I modified your settings file a little and then did the deconvolution myself and it works. I attach the modified settings file (called sets2mod.txt) and the commandline to use with it will be this:
deconvolve.exe fits 252 252 1 ImgConv.fit fits ImgDC.fit sets2mod.txt
This includes the use of CLViewer.exe (which I assume you have as it comes with the download). It is importnat to use this with the 252x252 pixel images you sent me as it runs slow enough for the CLViewer to safely update each iteration so you can see what is happenning. If you take my earlier advice and change to 256x256 pixel images then the chances are that deconvolution will progres too quickly for CLViewer to keep up using the current settings. If you want to do this then you are probably better off changi the setting:
[Output_every_lg] 1 1
to
[Output_every_lg] 1 2
to avoid too rapid readwrite requests for CLViewer.exe. Alternatively get rid of the viewer by changing
[Display_Program] CLViewer.exe
to
[Display_Program] None
Regarding your point about saving the PSF  the PSF is not saved to disk. It is the very same PSF you supply. Deconvolve.exe does not alter the PSF (only DeconBMI.exe and DeconVarBMI.exe do that).
Convolve.exe ought to be usable, but there is no option to set the psf as the file to deconvolve with instead of worsening the image by convolving, so I left this option at present. Finding the reciprocal might be an option, but I would need to do this in the frequency domain.
You are correct. Convolve.exe only does convoutions. Regarding inverse filtration, you will have access to all the Biaram programs that were designed for that such as MkLSIF.exe (see the Biaram Manual for more).
(I have some more photos with considerably long streaks due to camera shake, and it would be nice to know how to best get the psf to follow a linear curved path, perhaps by tracing from the image?)
In general I would advise you play with the algorithms on test objects (where you have introduced the blur yourself and you know the truth). Play with the settings, the boundary treatments, etc. until you are very familiar witht he programs and how to use them. Then you can start applying them to your real world images. Regarding camera shake  have you considered trying some of the third party freeware pointed to in the Deconvolve.net links page?
You mentioned that you use the DemoBlind package and substitute your own image in there. This will not work (the solution will be degenerate or be poor) unless you alter the settings to match the new image you use  in particular you must ensure the constraint settings are appropriate for your new input image  that is:
[Constraint__Img]
[Lower_Upper_val]
Please see the Biaram manual for details (Manual_BA.pdf).
Further general comment, I am quite familiar with Mathematica and have ...
With regards the general comments, I use C as this is what I was brought up on. I have never used or had access to Mathematica. I find C to be most flexible and allows me great algorithmic and programmatical freedom. The algorithms are very simple  they are the published deconvolution algorithms. To make them practically useful to people I have had to use C for I/O and various checks and balanaces.
Also curious about the lack of user discussion.
The website is relatively new (only been up for a couple of months). Also, I suppose many people don't like fora where they cannot be anonymous. Thank you for your contribution. I will put this up on the user forum site when I get a chance to do so so others can benefit from this exchange. I hope it has been helpful to you.

DR: Feedback (11/08/2010 05:40) 
Dear Dr Tadrous,
Thank you for your helpful response to my difficulties. It will probably take me another week to
look at all the points and suggestions, particularly regarding the constraints to the psf. For the
moment I am only sending you feedback on the BiaQIm deconvolution and settings file that you sent
me, as I have spent some time investigating this, so this is partial feedback, to let you know how
it has helped thus far.
I assumed that you meant me to open BiaQIm and load the settings file after selecting restoration,
iterative nonblind. The settings file seemed to overwrite anything I previously selected.
(However, I tried the command line that you suggested, run from a directory with the relevant files
and this seemed to give the same result too.)
On completion the image looked good, and as I was satisfied I tried doing the same with a
512 pixel image, very similar results, and a mistake, as subsequent analysis determined that
I should have looked at the first result more closely.
I used Mathematica to compute the psf that converts the original blurred image to the result
obtained using your settings file and BiaQIm on the 252 pixel image. ( This arose by accident
using Photopaint to increase the size from a previous image and loading my own, I 'knew' about
the 2^n fast algorithms, but its been so long, and I've been computing continuous functions of
frequency recently for a voice recognition algorithm, that I quite forgot to keep the information
active...)
The algorithm is this, Fourier(aperture function) = Fourier(blurred)/Fourier(cleaned) so I
divide the images in the frequency domain and convert back to get aperture function. This works
with any output image, so I don't require a psf from the programs.
The plot is shown in the attached jpg image, and I note that it is all nonnegative, but the
psf is symmetric, apart from two faint distant lines curving around. On inspection of the image
result this is seen, some sharpening, but the diagonal streak of blurring is still present. So I
have to conclude that the algorithm fails, or is incomplete, in this case. I need the large
central spike to be a line...
I enclose a 512 by 512 image. I did try this with the same settings, and it converges to
a similar result. The psf curved lines are there and also, in the image, excessive directional
enhancement in the direction opposite to the blur streak. I need to run this again to check all
was correct.
So I think maybe its best to concentrate on trying to obtain a better psf, something that
looks a bit like the known aperture function, which is a linear streak. Maybe it needs masks
to do this?
I did in fact try to use Mathematica to deconvolve using a guessed aperture function.
There is no difficulty doing this, but it seems that the result has excessive high frequency
noise, to the point where the low frequency image has totally vanished. I.e. its doing exactly
what is asked, but functions that are close in the aperture space don't yield solutions
that are close in the image space. I guess that the algorithms restrict aperture functions
to preserve continuity in both domains?

DR: More Feedback (13/08/2010 05:41) 
Dear Dr Tadrous,
I can now now give feedback for the constrained psf deconvolution using DemoBMI.bat or in other
words DemoBlind.zip with the modifications you mentioned, so as to specify a Blank Weights Border.
Before that though, I notice that BiaQIm converges to transfer functions with curved lines
round the sides, but some way from the center. I also see that if you take the reciprocal of the
Fourier transform of an asymmetric aperture function, and transform back, it is a characteristic signature
that reciprocals in the frequency domain introduce these lines, so I am wondering why these should
be appearing in the plots? I'll leave it as an open question.
One small point I noticed on rereading your comments is that I've been using the term
deconvolution and you prefer inverse filtration. I'll try to stick to the latter to avoid confusion. Also,
when doing inverse filtration from a psf I assume that this process has to use MkLSIF.exe to avoid the high
frequency noise I mentioned. If so, it would probably be useful to have a demo because there are settings
files involved and I find these take a lot more effort to cope with than command lines. I did have some
success with inverse filtration, but as the aperture function was only approximate I found it necessary
to introduce an extra convolution with gaussian aperture. In some cases this gets close to the
desired effect.
Ok, now I unzipped the third demo, the one that has a blurred text and cross shaped
aperture function, and placed an edited psf file there. This I derived from
the one you sent, but I set everything to zero at radius more than 12 pixels from the center, then
saved as doubles and converted to fit format. It looks ok with the viewer. For the image I initially
used a small 64 by 64. (Attached.) On running it clearly diverges and the psf is destroyed.
Making changes to the psf settings file to increase the blank border seems to have no
beneficial effect, divergence again.
Unfortunately I am finding that a knowledge of the exact mathematical process, the
relevent settings, and diagnostics for failed attempts are proving essential, and at the moment
I have none of these and am making very little progress.
(ImgConv2 atttached) Larger images seem to fail because the psf alternates between reasonable
approximations and ones that are spread out too far. Unfortunately I had little success imposing
the boundary constraints and usually ended up with something unrealistic and destroyed image.
Ok, the next thing I tried was the demo with the moon picture and small 17 pixel psf.
I edited this to correspond to the one I wanted and put in my image, trying to ensure that there
were large black areas. Long story short, problem was that the result had medium scale random
wave patterns, but as I did for some reason not get to see the intermediate images I don't know
if it over iterated.
The following I tried earlier on, and as its the end of the week I can only say that I found
how to do the edits for a 512 image, but that it failed to give a satisfactory result. I'll include it in
braces as there are some comments regarding the instructions in the manual.
{ Start braces
I also edited DCSetPSF.txt to have weights border
[BlankWghtBorder] YES 244 244 244
This should leave a 24 pixel square in the center for the evolution of the psf.
On reading the manual for DeconBMI I note that it makes a suggestion for using a good
psf estimate. I couldn't do this so ran it just by executing the batch file; see below.
Also, there are four numbers in the output. Sorry, I did see it mentioned what these were, but I have
lost the place again and it seems to be not in the manual.
Now, regarding using the good psf estimate, the manual states
"If you have a good estimate for the PSF (e.g. a measured PSF or one calculated using a good model
for your system) then it is better to start with the deconvolvedimagefinding step using your good PSF
estimate as the addtional input."
"so to effectively begin with the deconvolved image refining step first do a nonblind deconvolution
with your good PSF estimate and then use the outpt of this as input to DeconBMI (i.e. you manually
run the deconvolved image finding step first using nonblind deconvolution)."
So once one iteration is made, where does the aditional input go?
Also, the nonblind deconvolution in BiaQIm has a multitude of different methods and
options available, so am I supposed to derive these from somewhere in the settings files?
Ok, it takes a long time to complete each iteration and there was no way to anticipate
this, but after five I am getting a small psf and black processed image with regions of white dots.
The psf is a small butterfly shape in the right direction, but consists of only twelve pixels.
Also there is nothing on the graph output window.
It seems that something is going wrong.
} End braces
From my point of view, as a beginner, it would be useful to have a rough outline of
what the various methods are doing. Ordering all the books is going to prove quite expensive,
but I am doing some reserch on the internet, so hopefully my knowledge will improve.
However, as I mentioned before, there seems to be a lot of interaction needed with the
settings in the software, and this can only meaningfully take place with a good understanding
of the methods and implementation. I think you are right that the only reasonable solution
might be to try more simple examples in order to get to grips with what each of the programs
is doing, but from my point of view if I put this amount of time into the project I might also
consider writing my own code. The advantage of Mathematica is that it is actually fairly
easy to do this, but usually converting it to fast code is more of a problem.
I hope this feedback is useful and I expect I'll try some more examples next week
as I have another trip to do this weekend. The project is certainly proving useful in developing
my record keeping and report writing skills, but it can get quite tiring at the end of the day.
I started because I thought it ought to be possible to restore an image taken with
a sales telephone number on it, and it was unreadable. I could drive over and write it down
again, but I think I am learning more this way. However, I am wondering if the camera
introduces some distortion due to saturation or the small amount of image compression
that is used. It is 10.2 mega pixel and about 50% compression, but it may in fact be
lossless.

Dr Tadrous: Using the PSF (14/08/2010 11:41) 
Dear DR,
Thank you for your detailed feeback and comments. I am unable to go over them in detail at this time due to various pressures of my dayjob but I will try and have a look in more detail when I am get a chance. Until then, some of the questions you put I believe are answered in the detailed documentation of the software. Other issues you may resolve by taking my advice in trying the software with simple known examples and working up from there. Clearly there is a lot to learn about deconvolution theory  I've been studying it and programming algorithms for over 15 years  but I would need to write a small textbook if I were to answer all your queries about the algorithms (maybe one day I will do this but not in the near future)  however, you can find most of what you need to know online for free and at your local university library (you may find some of the references I give in the User's manuals a good place to start).
Regarding terminology, I use 'inverse filtering' to mean deconvolution by a onestep noniterative method (such as the use of convolution by an inverse filter PSF  which is what you alluded to in your original posting). Deconvolution is the overarching general term for all methods (whether inverse filterbased or iterative or other).
A few general points I would like to make after looking at the pictures you sent. Deconvolving real photographs must take careful attention to noise content and appropriate steps taken to minimise the amplification of noise (this may be one reason why your results degenerate). Another is consideration of depth of focus  foreground structures may be less or more blurred (or both) than background structures  or vice versa. This is a phenomenally difficult challenge which may not be soluble with my software packages as they stand (with the possible exception of DeconVarBMI  which is a really advanced algorithm and even I have little experience with it). Boundary treatments can also have a profound effect on the results of any deconvolution  especially blind methods. It seems to me that, as a selfconfessed 'beginner', you are actually attempting to do a very advanced deconvolution problem (advanced in terms of mathematical difficulty  but perfectly
understandable as a goal  you just want to deblur the picture). Note that when you restrict the PSF changeing in blind deconvolution you will need to consider the effect of this on the flux conservation rules of the algorithm  failure to adequately take this into account is another source of deconvokution failure.
I wrote the programs with lots of settings to give the user this great flexibility over the use of the programs (something you just don't get with commercial 'packages' which are therefore more 'userfriendly'). This should allow you to 'learn by playing' without having to code your own software. However, you may find in the end that that is a better way for you to learn the basics since you are already familiar with Mathematica coding.
I am sorry not to be of more help. I hope you succeed in your efforts.

