I took the image below:
Divided it into 8X8
tiles, did a 2D DCT transform on each tile and chopped them to only the first 30
coefficients on each axis. Now I'm trying to visualize the result as an image that will help my intuition on the DCT plane.
Problems:
(0,0)
is way larger than all the others So far, the best transform I found is below:
def visualize_dct(d):
d = np.log(abs(d).clip(0.1))
maxi, mini = d.max(), d.min()
d = 255*(d - mini)/(maxi-mini)
return d
Which gave me the image below:
Full code here: http://nbviewer.ipython.org/github/ihadanny/my-py-notebooks/blob/master/img_processing_04.ipynb
Any better ideas?
Found it: what I was looking for is histogram equalization. The implementation is quite straight forward:
def visualize_dct(d):
d = d + abs(d.min())
h = np.histogram(d, bins=1000, range=(0, d.max()))
c = 255.0*np.cumsum(h[0])/sum(h[0])
new_img = np.zeros(d.shape)
for index,value in np.ndenumerate( d ):
new_img[index] = c[999.0*value/d.max()]
return new_img
result for a single tile:
and for the whole image:
(notice the difference between the simple tiles and the ones with lots of details)