back to iatexture

Function quantimg

Synopse

The quantimg function performs an image quantization.

  • g = quantimg(f,rate)
    • Output
      • g: output image
    • Input
      • f: ndarray: input image.
      • rate: rate of the image quantization

Description

The quantimg function computes an image quantization.

Function Code

1. from ia636 import ianormalize
2. 
3. def quantimg(f,rate):
4.     #nc = 2**rate
5.     #return ianormalize(f,[0,nc-1])
6.     #return f /(256/nc)
7.     return f >> (8 - rate)

Example

01. from iatexture import *
02. import ia636
03. 
04. f = adread('cameraman.tif')
05. print type(f)
06. h = ia636.iahistogram(f)
07. adshow(f,'original image')
08. adshow(ia636.iaplot(h),'histogram')
09. print 'min/max:',f.min(),'/',f.max()
10. f4 = quantimg(f,4)
11. h4 = ia636.iahistogram(f4)
12. adshow(f4,'image quantization 4 bits/pixel')
13. adshow(ia636.iaplot(h4),'histogram quantization 4 bits/pixel')
14. print 'min/max:',f4.min(),'/',f4.max()
15. f5 = quantimg(f,5)
16. h5 = ia636.iahistogram(f5)
17. adshow(f5,'image quantization 5 bits/pixel')
18. adshow(ia636.iaplot(h5),'histogram quantization 5 bits/pixel')
19. print 'min/max:',f5.min(),'/',f5.max()
20. f6 = quantimg(f,6)
21. h6 = ia636.iahistogram(f6)
22. adshow(f6,'image quantization 6 bits/pixel')
23. adshow(ia636.iaplot(h6),'histogram quantization 6 bits/pixel')
24. print 'min/max:',f6.min(),'/',f6.max()
<type 'numpy.ndarray'>
min/max: 0 / 251
min/max: 0 / 15
min/max: 0 / 31
min/max: 0 / 62

original image

histogram

image quantization 4 bits/pixel

histogram quantization 4 bits/pixel

image quantization 5 bits/pixel

histogram quantization 5 bits/pixel

image quantization 6 bits/pixel

histogram quantization 6 bits/pixel