天天看点

第2章 Python 数字图像处理(DIP) --数字图像基础1 - 视觉感知要素 - 亮度适应与辨别视觉感知要素

数字图像基础1

  • 视觉感知要素
      • 亮度适应与辨别
import sys
import numpy as np
import cv2
import matplotlib 
import matplotlib.pyplot as plt
import PIL
from PIL import Image

print(f"Python version: {sys.version}")
print(f"Numpy version: {np.__version__}")
print(f"Opencv version: {cv2.__version__}")
print(f"Matplotlib version: {matplotlib.__version__}")
print(f"Pillow version: {PIL.__version__}")
           
Python version: 3.6.12 |Anaconda, Inc.| (default, Sep  9 2020, 00:29:25) [MSC v.1916 64 bit (AMD64)]
Numpy version: 1.16.6
Opencv version: 3.4.1
Matplotlib version: 3.3.2
Pillow version: 8.0.1
           
def normalize(mask):
    return (mask - mask.min()) / (mask.max() - mask.min() + 1e-5)
           

视觉感知要素

亮度适应与辨别

第二种现象称为同时对比,即一个区域的感知亮度并不只是取决于其灰度,如下图,所有的中心方块都有完全相同的灰度,但当背景变得较亮时,它们在眼睛中会变得更暗。

# 同时对比
height, width = 512, 512
mid_h, mid_w = height//2 + 1, width//2 + 1 # 按书上公式floor(M/2) + 1

img_ori = np.zeros([height, width], dtype=np.float)
img_ori = (img_ori + 1.0) * 1.
temp = np.ones([200, 200]) * 128.

img_1 = img_ori.copy() * 50. 
img_1[mid_h-100:mid_h+100, mid_w-100:mid_w+100] = temp

img_2 = img_ori.copy() * 1.
img_2[mid_h-100:mid_h+100, mid_w-100:mid_w+100] = temp

img_3 = img_ori.copy() * 240.
img_3[mid_h-100:mid_h+100, mid_w-100:mid_w+100] = temp

plt.figure(figsize=(15, 5))
# plt.subplots_adjust(wspace=0.05)
plt.subplot(131), plt.imshow(Image.fromarray(img_1), 'gray'), plt.xticks([]), plt.yticks([])
plt.subplot(132), plt.imshow(Image.fromarray(img_2), 'gray'), plt.xticks([]), plt.yticks([])
plt.subplot(133), plt.imshow(Image.fromarray(img_3), 'gray'), plt.xticks([]), plt.yticks([])
plt.tight_layout()
plt.show()
           
第2章 Python 数字图像处理(DIP) --数字图像基础1 - 视觉感知要素 - 亮度适应与辨别视觉感知要素

继续阅读