第2章 Python 数字图像处理(DIP) --数字图像基础2 - 图像感知要素 - 图像取样和量化 - 空间分辨率和灰度分辨率

图像感知与获取

一个简单的成像模型

我们用形如 f ( x , y ) f(x,y) f(x,y) 的二维函数来表示图像。在空间坐标 ( x , y ) 处 f (x, y)处 f (x,y)f的值是一个标量,其物理意义由图像源决定,其值与物理源(如电磁波)辐射的能量成正比。因此, f ( x , y ) f(x,y) f(x,y) 一定是非负的和有限的,即
0 ≤ f ( x , y ) < ∞ (2.3) 0 \leq f(x, y) < \infty \tag{2.3} 0f(x,y)<(2.3)
函数 f ( x , y ) f(x, y) f(x,y) 由两个分量表征:(1)入射到被观察场景的淘汰照射量;(2)被场景中物体反射的照射量。它们分别称为入射分量反射分量,并分别用 i ( x , y ) 和 r ( x , y ) i(x, y) 和 r(x, y) i(x,y)r(x,y) 表示。这两个函数的乘积形成 f ( x , y ) f(x, y) f(x,y) ,即
f ( x , y ) = i ( x , y ) r ( x , y ) (2.4) f(x, y) = i(x, y) r(x, y) \tag{2.4} f(x,y)=i(x,y)r(x,y)(2.4)
0 ≤ i ( x , y ) < ∞ (2.5) 0 \leq i(x, y) < \infty \tag{2.5} 0i(x,y)<(2.5)
0 ≤ r ( x , y ) ≤ 1 (2.6) 0 \leq r(x, y) \leq 1 \tag{2.6} 0r(x,y)1(2.6)

于是,反射分量限制在0(全吸收)和1(全反射)之间。 i ( x , y ) i(x, y) i(x,y)的性质取决于照射源,而 r ( x , y ) r(x, y) r(x,y) 的性质取决被成像物体的特性。

区间 [ L m i n , L m a x ] [L_{min}, L_{max}] [Lmin,Lmax]称为亮度级(或灰度级)

图像取样和量化

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()

在这里插入图片描述

空间分辨率和灰度分辨率

空间分辨率是图像中最小可辨别的希腊别人测度。这一测度通常使用点数/英寸(dpi)表示。

灰度分辨率是批在灰度级中可分辨的最小变化。灰度级通常是2的整数次幂。最常用的数是8比特,在一些特定的范围也使用16比特。32比特的灰度量化很少见,有时也会使用10比特和12比特来做数字化图像灰度级的系统。我们常说一幅灰度被量化为256组的图像,其灰度分辨率为8比特。灰度的可分辨变化 不仅受噪声和饱和度的影响,而且受人类分析和解释整个场景内容的感知能力的影响。

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()

在这里插入图片描述

# 改变灰度值以实现灰度级的不同
# 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()

在这里插入图片描述

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jasneik

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值