轉(zhuǎn)載請注明出處
圖像感知與獲取
一個簡單的成像模型
我們用形如 的二維函數(shù)來表示圖像。在空間坐標(biāo)
的值是一個標(biāo)量,其物理意義由圖像源決定,其值與物理源(如電磁波)輻射的能量成正比。因此,
一定是非負(fù)的和有限的,即
函數(shù) 由兩個分量表征:(1)入射到被觀察場景的淘汰照射量;(2)被場景中物體反射的照射量。它們分別稱為入射分量和反射分量,并分別用
表示。這兩個函數(shù)的乘積形成
,即
于是,反射分量限制在0(全吸收)和1(全反射)之間。的性質(zhì)取決于照射源,而
的性質(zhì)取決被成像物體的特性。
區(qū)間稱為亮度級(或灰度級)
圖像取樣和量化
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