3

I took the image below:

lizzards

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:

  • The DCT coefficient of (0,0) is way larger than all the others
  • I want to see a difference between positive and negative coefficients.

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:

dct_visualized

Full code here: http://nbviewer.ipython.org/github/ihadanny/my-py-notebooks/blob/master/img_processing_04.ipynb

Any better ideas?

alyssaeliyah
  • 2,214
  • 6
  • 33
  • 80
ihadanny
  • 4,377
  • 7
  • 45
  • 76

2 Answers2

4

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:

tile tile_dct

and for the whole image:

whole_image whole_image_dct

(notice the difference between the simple tiles and the ones with lots of details)

ihadanny
  • 4,377
  • 7
  • 45
  • 76
1

You could shift the values, so that all are positive; then take the individual logarithm (which, by the way, is the basis for conversion to dB), and plot that as colors.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • tried your suggestion and it looks very flat :( did you mean this? d = d + abs(d.min()) + 1.0; d = np.log(d); maxi, mini = d.max(), d.min(); d = 255*(d - mini)/(maxi-mini); – ihadanny Feb 07 '15 at 17:38