Skip to content

Commit 3ace2ef

Browse files
committed
Add Image_Transformations
I am trying to get a better idea of what happens with the transforms by looking at the images as they go through various stages. My first step of checking out if I can get illumination from original image and filtered "reflectance". I messed it up, as you can the illunimation looks nothing like how its supposed to look, I should rethink on the illumination-reflectance model itself. Signed-off-by: Aditya A Prasad <[email protected]>
1 parent 062ef95 commit 3ace2ef

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
lines changed

DCT.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
import matplotlib.pyplot as plt
77
from scipy import fftpack
8-
import urllib2
8+
from urllib.request import urlopen
99
import IPython
1010

1111
# [Source](http://bugra.github.io/work/notes/2014-07-12/discre-fourier-cosine-transform-dft-dct-image-compression/)
@@ -15,7 +15,7 @@
1515
image_url='file:///C:/Users/Aditya/Pictures/crazygirl.jpg'
1616
# reads the image from url using PIL and converting it into a numpy array after converted grayscale image.
1717
def get_image_from_url(image_url='http://i.imgur.com/8vuLtqi.png', size=(128, 128)):
18-
file_descriptor = urllib2.urlopen(image_url)
18+
file_descriptor = urlopen(image_url)
1919
image_file = io.BytesIO(file_descriptor.read())
2020
image = Image.open(image_file)
2121
img_color = image.resize(size, 1)

Image_Transformations.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from urllib.request import urlopen
2+
import io
3+
from PIL import Image
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
7+
# Image Transformations
8+
original_image ='http://i.imgur.com/GAazZeX.png'
9+
after_homo = 'http://i.imgur.com/KqMjJWV.png'
10+
11+
def get_image(image_url='http://i.imgur.com/8vuLtqi.png', size=(128, 128)):
12+
file_descriptor = urlopen(image_url)
13+
image_file = io.BytesIO(file_descriptor.read())
14+
image = Image.open(image_file)
15+
img_color = image.resize(size, 1)
16+
img_grey = img_color.convert('L')
17+
img = np.array(img_grey, dtype=np.float)
18+
# This returns a 128*128 size matrix
19+
return img
20+
21+
np_image_before = get_image(original_image,(384,510))
22+
np_image_after = get_image(after_homo,(384,510))
23+
24+
print("\nWe have the greyscale version of the original image image of size - "+str(np_image_before.shape))
25+
print(np_image_before)
26+
print(np.max(np_image_before))
27+
print(np.min(np_image_before))
28+
29+
print("\nWe have the greyscale version of the image after filtering of size - "+str(np_image_after.shape))
30+
print(np_image_after)
31+
print(np.max(np_image_after))
32+
print(np.min(np_image_after))
33+
34+
35+
img_before = Image.fromarray(np_image_before)
36+
img_before.show()
37+
38+
img_after = Image.fromarray(np_image_after)
39+
img_after.show()
40+
41+
# This is consistent with the actual image as we have 250 as the whitest pixel while after filtering its 114 (no really white area after filtering)
42+
print("\n\nSo as we can see larger values closer to 256 is white, smaller values close to 0 are black")
43+
# if you are confused about the white edges as seen in the image and the numpy array - its because i couldnt crop it properly.
44+
45+
'''
46+
Okay so reflectence is what we get after filtering - 'np_image_after' - r(x,y)
47+
? or is it, maybe its original-filtered or something?
48+
49+
and image itself is 'np_image_before' - i(x,y)
50+
51+
Based on the illumination-reflectance model of images, we can find illumination by dot division
52+
'''
53+
np_image_illumination = np.divide(np_image_before,np_image_after)
54+
print(np_image_illumination)
55+
56+
img_illumination = Image.fromarray(np_image_illumination)
57+
img_illumination.show()

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# Image-Processing-
1+
# Image-Processing
22
IC 040 IMAGE PROCESSING - Code Samples for concepts learned while pursuing this elective
33

44
## Homomorphic filtering
55

6+
I thank Steve Eddins, for his [blog post](http://blogs.mathworks.com/steve/2013/06/25/homomorphic-filtering-part-1/) on this.
7+
68
In case of homomorphic filtering, I am taking the image into the log domain so as to seperate the illumination and the reflectance of the image (Multiplicative model).
79

810
As the irregualar illumination varies slowly and reflectance (property if the object being imaged) varies with a high frequency when we look at it with respect to the spatial domain.
@@ -11,4 +13,15 @@ After running my code I get this
1113

1214
![comparison of before and after homomorphic filtering](http://i.imgur.com/INI4d5W.png?1)
1315

14-
As you can see the illumination is regular across the image. Thus we have removed the multiplicative noise.
16+
As you can see the illumination is regular across the image. Thus we have removed the multiplicative noise.
17+
18+
## DCT
19+
20+
This is the code I got from [here](http://bugra.github.io/work/notes/2014-07-12/discre-fourier-cosine-transform-dft-dct-image-compression/), I used it to get great insight into DCT. I added some comments to understand it better.
21+
22+
23+
## Image Transformations
24+
25+
The plan is to explore the equations relating to the various transforms using actual images - numpy arrays.
26+
27+
My first attempt is at getting the illumination - from the homomorphic filtered - before and after image.

homomorphic_filtering.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
N = 2*size(I,2) + 1;
2323

2424
% standard deviation of the equivalent spatial domain gaussian filter ??
25-
sigma = 10;
25+
sigma = 30;
2626

2727
% X and Y are k*k size matrices with
2828
% X has column i with all i's (this is true for i = 1,....k

0 commit comments

Comments
 (0)