Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ใช้ Pseudocolor กับภาพใน Matplotlib

Pseudocolor เหมาะกับภาพ grayscale (single channel) เพิ่มคอนทราสต์ ใช้ imshow() กับ colormap ต่างๆ

ตัวอย่างโค้ด


from matplotlib import pyplot as plt, image as mimg

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

img = mimg.imread('bird.jpg')
lum_img = img[:, :, 0]  # เลือก channel เดียว
plt.imshow(lum_img)
plt.axis('off')
plt.show()

ผลลัพธ์

ภาพ grayscale แสดงด้วย colormap default (viridis)

ใช้ Pseudocolor กับภาพใน Matplotlib