(Warning Addendum: This will consume a lot of Data/Bandwidth)
$Why? \, because \, I \, can$
As promised from last post, here are some test patterns and their Fourier Transforms.
As the patterns are tweaked, their FT's also change.
I'm not really good at explaining so, I'll let the images speak for themselves.
Is it moving yet?
This is a 11.1 MB upload so let it load for a bit
$Unless \, your \, internet \, has \, transcended \, Philippine \, standards$
Now, what happens if we combine some of these patterns, say two sinusoids?
As a Physics major I should know the property of Fourier Transform that
$\mathcal{F} \{ f(x)g(x) \} = F(k)*G(k)$
where
$F(k) = \mathcal{F}\{ f(x) \} $
Simply put, the FT of the product of two functions is the convolution of their separate FT's.
$G(k) = \mathcal{F}\{ g(x) \} $
Like so
Woah! Hold on there. What is this convolution? Well... umm...
I'm not sure how mathematicians define convolution (a quick Google search is not helping and I don't want to search for longer than quick.) But in my own words I'd say convolution is like an element-wise operation where each element of A is multiplied to the whole of B.
That's not helping. English please. Uh......
Okay so I have two images A and B. Now imagine all white dots on A suddenly looks like B.
$BOOM \, CONVOLUTION$
Well I hope this makes things clearer
The thing here is that when the points are spaced too closed to each other, the resulting convolution pattern will have overlapping images of the sample pattern.
In the previous entry, we found out that using Fourier Transform we can find certain features in an image. That's quite useful for image recognition or just plain cheating in Finding Waldo or those I Spy-like games.
What else can we use FT for then?
Filtering out noise, that's what.
Have you ever put your thumb mark on something and it looked too light. Or maybe it was too dark and smudgy? Eitherway it just looked kinda wrong.
Then FT is fourier. $Josh \, STAHP$
So here's a thumbmark
Looks a bit too light, right? And look at all those white spots
Let's look at the FT of this fingerprint
$Looks \, like \, a \, galaxy. \, COOL!$
Now lets remove everything else
(except the middle, let's keep some of that)
(credits to Kit Guial for pointing out that a small fraction instead of 0's in the middle is better)
Now let's transform it back into an image
(after hours of tweaking the mask parameters)
Well?
That looks worse!
Hold your horses, judging cowboy. It's just a contrast issue. Let me fix that for you.
Better?
Cleaning in Fourier space does not make it instantly better. It just removes the noisy elements.
Now we can get a much cleaner binarized image.
Now lets try it on a picture $FROM \, THE \, MOON$.
(read that again in an ominous echoing voice)
(better? alright we can move on)
See those horizontal lines? Annoying.
Horizontal lines? $EZ$ Those are just dots along the y-axis.
I'm not even gonna post the FT and mask images.
I basically just made two black vertical line along the middle of the Fourier transform before turning it back into an image. (Making sure there is a gap in the center.) I tried to vary the length of the line as well as the size of the gap in the middle but there is not much difference observed.
Ahh much better.
Now let's see if we can separate a painting from its canvas
Behold an amazing 100% authentic Daria painting
I know some of my classmates drew masks manually but I felt lazy doing that.
So I created masks using varying thresholds.
In fact I'm getting a bit lazy in writing as of now.
So again I'll let the pictures talk for themselves.
As I reduce the threshold, more of the "canvas" features are removed. At the same time more of the painting features are removed. So in the end we have to compromise between canvas noise and missing painting.
Personally my favorite is using a threshold value of 0.57, which looks like this
Taking the FT of the color-inverted mask we get
Surprise! It's the canvas pattern.
Finally, since this is a painting, it does not do justice if we do not return the color.
I split the original image into its R,G,B channels using GIMP.
I applied the same technique on the three channels to remove the canvas pattern.
I applied the same technique on the three channels to remove the canvas pattern.
The final colored image was then obtained by storing the three cleaned channels into an RGB image.
And voila
Here is the restored image using threshold value = 0.57
along with the original for comparison
Hooboy. That's finally over.
I found this topic to be really cool.
So much so that I ended up playing with it too much.
So yeah...
Spongebob won't be returning because this one took me a lot more than 5 hours of "blogging" (that includes generating more pretty images).
I would like to thank Kit again for the fingerprint advice,
and Roland for tips on general array handling in Scilab. (I still hate you scilab)
Overall I am again, giving myself a solid 11/10! $wagoom$
No comments:
Post a Comment