Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 831 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Image Deconvolution/"Sharpening" #373130
06/07/11 19:38
06/07/11 19:38
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Hey folks,

I thought I could annoy you with another of my more or less brilliant ideas. I won't bother you with the mathematical details this time, though, and just present you some result. Maybe someone is interested.

1) first line are blurred with a gaussian filter, radius 5,9 and 17, the next three rows show the blurred image after my deconvolution filter was applied to it n times (n=1,10 and 100). this filter is some kind of "brute force" approach.


2) going to frequency space, a mathematically way more elegant approach. note that the image is only reconstructible because there is no noise present. also, it has 16 bit depth.


3) frequency space, this time downsampled to 8 bit (introducing noise). so this would definately be a real world example and possible with my filter.


I know I know I should stop posting stuff like that here... well. But I had these images anyway.
Joey

Re: Image Deconvolution/"Sharpening" [Re: Joey] #373132
06/07/11 19:55
06/07/11 19:55
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
Thats cool indeed! Did you try to scale up a texture to a higher resolution using this technique?
Would be great if you post some info about the math behind. wink

Re: Image Deconvolution/"Sharpening" [Re: Hummel] #373135
06/07/11 20:08
06/07/11 20:08
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
rescaling wouldn't work as the filter can only reconstruct information that has formerly been present. I got the idea when doing an astronomy course, using a telescope's point spread function to estimate what the stars looked like before they passed the optics.
Convolution in fourier space is a multiplication, thus "undoing" it can be acheived by simply dividing out the convolution. So the process is
Image --FT--> Spectrum
Spectrum/=Convolution Kernel --FT--> Reconstructed Image
As I know the point spread function (the gaussian matrix used for smoothing it in first place) this process is really easily done, you can look up "Wiener filter" on Wikipedia if you're familiar with some analysis:
http://en.wikipedia.org/wiki/Wiener_deconvolution
As I said, noise makes the thing way more difficult, that's where the ringing effects in the first pictures come from.

The first images don't go through fourier transformation, so I need to iterate an estimate. The algorithm is known as "Richardson-Lucy" for those who are interested in it.

There's also something called "blind deconvolution", which tries to estimate the psf from the source material itself. For stars it's pretty straightforward, since you "know" their shapes. I haven't found out how to do it properly for a normal image, though.

Re: Image Deconvolution/"Sharpening" [Re: Joey] #373140
06/07/11 20:18
06/07/11 20:18
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
Are you willing to give out some source code?

Re: Image Deconvolution/"Sharpening" [Re: Hummel] #373141
06/07/11 20:19
06/07/11 20:19
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Sure, you can have the whole source code, but it's written in mathematica.

Re: Image Deconvolution/"Sharpening" [Re: Joey] #373142
06/07/11 20:24
06/07/11 20:24
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
shouldn´t hurt, shall I PM you?

Re: Image Deconvolution/"Sharpening" [Re: Hummel] #373144
06/07/11 20:30
06/07/11 20:30
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
No, I can post it here, my notebooks are a mess anyway wink.
1st one
Code:
normalize[mat_] := mat/Total[Total[mat]];
deconv[i0_, k_, n_, count_] := 
 Module[{i = i0}, 
  Do[i = ImageAdd[i0, 
     ImageConvolve[i, 
      normalize[BoxMatrix[0, 2*n + 1]] - normalize[k[n]]]], {count}];
  i
  ];
source = Import["ExampleData/lena.tif"];
g0 = ImageConvolve[source, normalize[BoxMatrix[1]]]
deconv[g0, BoxMatrix, 1, 10]



2nd one
Code:
size = 128;
imagesize = size*2 + 1;
total[mat_] := Total[Total[mat]];
normalize[mat_] := mat/total[mat];

(* load data, make ft, inverse ft *)
image = ImageResize[ExampleData[{"TestImage", "Lena"}], imagesize]
data = ImageData[image];
col = First[ImageDimensions[image]]
row = Last[ImageDimensions[image]]
px = col*row;
f = Partition[Take[Flatten[data], {2, px*3, 3}], col];
fourier = Fourier[f, FourierParameters -> {0, 1}];
intensity = total[f];
Image[Abs[
  RotateRight[fourier, {IntegerPart[row/2], IntegerPart[col/2]}]]]
Image[Abs[InverseFourier[fourier]]]

(* load convolution kernel in fs *)
blurfunction = 
  RotateRight[
   Transpose[RotateRight[GaussianMatrix[{size, 30}], size]], size];
ListPlot3D[blurfunction, PlotRange -> All]

(*blur image, comparison with original*)
resetIntensity[mat_] := normalize[mat]*intensity;
blurred = fourier*blurfunction;
blurredImage = Image[resetIntensity[
   Abs[InverseFourier[blurred]]
   ]]

(*undo blur*)
reconstructed = blurred/blurfunction;
Image[resetIntensity[
  Abs[InverseFourier[reconstructed]]
  ]]


I hope the code works. It relies quite a bit on the mathematica stuff but it should be no problem to do it in another language.

Re: Image Deconvolution/"Sharpening" [Re: Joey] #373151
06/07/11 21:11
06/07/11 21:11
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
argh, I actually hoped to see how this fourier stuff works in practice -.-

Re: Image Deconvolution/"Sharpening" [Re: Hummel] #373162
06/07/11 21:42
06/07/11 21:42
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
just use any fft lib...

Re: Image Deconvolution/"Sharpening" [Re: Joey] #373167
06/07/11 22:30
06/07/11 22:30
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
really interesting stuff, too bad i can't study the subject in depth atm. however, it would be nice if you could take your time to answer a couple of questions that i came up with at the first glance laugh

-are there any methods for reconstruction without any a priori knowledge about the convolution kernel?
-have you tried measuring source and blurred images' entropy and\or other information parameters? (although i'm pretty sure that they'll be the same)
-how fast does this method degradate with appearance of noise?

Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1