第2章 Python 數(shù)字圖像處理(DIP) --數(shù)字圖像基礎(chǔ)2 - 圖像感知要素 - 圖像取樣和量化 - 空間分辨率和灰度分辨率

轉(zhuǎn)載請注明出處

圖像感知與獲取

一個簡單的成像模型

我們用形如 f(x,y) 的二維函數(shù)來表示圖像。在空間坐標(biāo) (x, y)處 f的值是一個標(biāo)量,其物理意義由圖像源決定,其值與物理源(如電磁波)輻射的能量成正比。因此,f(x,y) 一定是非負(fù)的和有限的,即
0 \leq f(x, y) < \infty \tag{2.3}
函數(shù)f(x, y) 由兩個分量表征:(1)入射到被觀察場景的淘汰照射量;(2)被場景中物體反射的照射量。它們分別稱為入射分量反射分量,并分別用i(x, y) 和 r(x, y) 表示。這兩個函數(shù)的乘積形成f(x, y) ,即
f(x, y) = i(x, y) r(x, y) \tag{2.4}
0 \leq i(x, y) < \infty \tag{2.5}
0 \leq r(x, y) \leq 1 \tag{2.6}

于是,反射分量限制在0(全吸收)和1(全反射)之間。i(x, y)的性質(zhì)取決于照射源,而 r(x, y) 的性質(zhì)取決被成像物體的特性。

區(qū)間[L_{min}, L_{max}]稱為亮度級(或灰度級)

圖像取樣和量化

def get_circle(height, width):
    """
    creat a circle faded image
    :param height: input height of the image you want to create
    :param width: input height of the image you want to create
    :return: image normalize [0, 1]
    """
    
    M, N = width, height
    u = np.arange(M)
    v = np.arange(N)
    u, v = np.meshgrid(u, v)
    D = np.sqrt((u - (M//2 + 1))**2 + (v - (N//2 + 1))**2)
    kernel = normalize(D)
    
    return kernel
# 圖像取樣
height, width = 512, 512
mid_h, mid_w = height//2 + 1, width//2 + 1

img_ori = np.zeros([height, width], dtype=np.float)
img_ori = (img_ori + 1.0) * 1.
circle = 1 - get_circle(400, 400)

img_ori[mid_h-200: mid_h+200, mid_w-200:mid_w+200] = circle

f_x_57 = img_ori[57:58, :] # 取樣 f(x, 56)

plt.figure(figsize=(10, 5))
plt.subplot(121), plt.imshow(img_ori, 'gray'), plt.xticks([]), plt.yticks([])
plt.subplot(122), plt.plot(f_x_57[0]), plt.xticks([]), plt.yticks([])
plt.tight_layout()
plt.show()
image

空間分辨率和灰度分辨率

空間分辨率是圖像中最小可辨別的希臘別人測度。這一測度通常使用點數(shù)/英寸(dpi)表示。

灰度分辨率是批在灰度級中可分辨的最小變化?;叶燃壨ǔJ?的整數(shù)次冪。最常用的數(shù)是8比特,在一些特定的范圍也使用16比特。32比特的灰度量化很少見,有時也會使用10比特和12比特來做數(shù)字化圖像灰度級的系統(tǒng)。我們常說一幅灰度被量化為256組的圖像,其灰度分辨率為8比特?;叶鹊目煞直孀兓?不僅受噪聲和飽和度的影響,而且受人類分析和解釋整個場景內(nèi)容的感知能力的影響。

def down_sample(image):
    height, width = image.shape[:2]
    dst = np.zeros([height//2, width//2])
    dst = image[::2, ::2]
    return dst
# 用降采樣來模擬降低空間分辨率的效果
img = cv2.imread('DIP_Figures/DIP3E_Original_Images_CH02/Fig0220(a)(chronometer 3692x2812  2pt25 inch 1250 dpi).tif', 0)

img_2 = down_sample(img)
img_3 = down_sample(img_2)
img_4 = down_sample(img_3)

plt.figure(figsize=(15, 18))
plt.subplot(221), plt.imshow(img, 'gray'), plt.xticks([]), plt.yticks([])
plt.subplot(222), plt.imshow(img_2, 'gray'), plt.xticks([]), plt.yticks([])
plt.subplot(223), plt.imshow(img_3, 'gray'), plt.xticks([]), plt.yticks([])
plt.subplot(224), plt.imshow(img_4, 'gray'), plt.xticks([]), plt.yticks([])
plt.tight_layout()
plt.show()
image
# 改變灰度值以實現(xiàn)灰度級的不同
# img = cv2.imread('DIP_Figures/DIP3E_Original_Images_CH02/Fig0222(a)(face).tif', 0)
img = get_circle(1000, 1000)

img_temp = normalize(img)

fig = plt.figure(figsize=(13, 26))
for i in range(8):
    ax = fig.add_subplot(4, 2, i+1)
    if i < 7:
        dst = np.uint(img_temp * (2**(8 - i) - 1))
    else:
        dst = np.uint(img_temp * (2))
    ax.imshow(dst, 'gray')
    ax.set_title(f'{2**(8 - i)}')
    ax.set_xticks([])
    ax.set_yticks([])
plt.tight_layout()
plt.show()
image
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請通過簡信或評論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容