量化
量化:计算机软件得到了一个样本点(图片)的数据,然后它要用多少个二进制位去表示它(重现图片)。如下图
根据上图,可以知道图像有一个灰度的概念
1bit 只有 2 个灰度级,0 和 1
2bit 有 4 个灰度级,0, 1, 2, 3
8bit 有 256 个灰度级,0 到 255
那么怎么使用MATLAB来进行量化呢?这里我们可以直接利用histeq()函数进行。
上代码:
t=imread('a1.jpg')
t1=rgb2gray(t)
t2=histeq(t1,256)
t3=histeq(t1,128)
t4=histeq(t1,64)
t5=histeq(t1,32)
t6=histeq(t1,16)
t7=histeq(t1,2)
t7=histeq(t1,2)
subplot(2,3,1),imshow(t2),title('量化级为256')
subplot(2,3,2),imshow(t3),title('量化级为128')
subplot(2,3,3),imshow(t4),title('量化级为64')
subplot(2,3,4),imshow(t5),title('量化级为32')
subplot(2,3,5),imshow(t6),title('量化级为16')
subplot(2,3,6),imshow(t7),title('量化级为2')%也就是二值图
效果图:
总结:histeq(I,n)
其中I为图像元素,n为量化级数,比如n为256,那么将其灰度值分为256级,若为2,则分为2级,即只有0,1(其实是0-127理解为0,其余为1,因为灰度值一共是0–255)之分,即会得到二值图(黑白图)