Image Basic
图像的基本概念
Image
图像就是数组,每个像素点的颜色是响应值。

Code
import skimage.data as data
from PIL import Image
image = Image.fromarray(data.astronaut())
image.show()skimage.data模块有很多demo 图片python
print(data.__all__)
['astronaut', 'binary_blobs', 'brain', 'brick', 'camera', 'cat', 'cell', 'cells3d', 'checkerboard', 'chelsea', 'clock', 'coffee', 'coins', 'colorwheel', 'data_dir', 'download_all', 'eagle', 'file_hash', 'grass', 'gravel', 'horse', 'hubble_deep_field', 'human_mitosis', 'immunohistochemistry', 'kidney', 'lbp_frontal_face_cascade_filename', 'lfw_subset', 'lily', 'logo', 'microaneurysms', 'moon', 'nickel_solidification', 'page', 'palisades_of_vogt', 'protein_transport', 'retina', 'rocket', 'shepp_logan_phantom', 'skin', 'stereo_motorcycle', 'text', 'vortex']Sampling
采样:从连续信号到离散信号。

Code
import numpy as np
import matplotlib.pyplot as plt
def generate_image(width, height):
I = np.zeros((width, height))
for x in range(width):
for y in range(height):
I[x, y] = np.cos(x/width*2*np.pi) * np.cos(y/height*2*np.pi) * 255
return I
def plot(index,n):
plt.subplot(1,4,index+1)
plt.imshow(generate_image(n, n), cmap='gray')
plt.title(f"{n}x{n}")
plt.axis('off')
for i,n in enumerate([5,15,50,1000]):
plot(i,n)
plt.show()Quantization
量化:用多少比特代表每个像素的颜色。

Code
import numpy as np
import matplotlib.pyplot as plt
def generate_image(level):
I = np.zeros((16,256))
for x in range(256):
n = 2**level # 一共多少个格子
length = int(256/n) # 每个格子有多大
I[:, x] = int(x/length) / n
return I/np.max(I)
def plot(index,level):
plt.subplot(4,1,index+1)
plt.imshow(generate_image(level), cmap='gray', vmax=1, vmin=0)
plt.title(f"level = {level}")
plt.axis('off')
for index,level in enumerate([1,2,4,8]):
plot(index,level)
plt.show()Neighbor and Distance
邻域:4 邻域(上下左右),D 邻域(四个角),8 邻域(4+D)
欧氏距离:De=(x−s)2+(x−t)2
D4距离:D4=∣x−s∣+∣y−t∣
D8距离:D8=max(∣x−s∣+∣y−t∣)
最后更新于
这有帮助吗?