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

วิธีพลอต Hysteresis Threshold ใน Matplotlib

ในการพลอต hysteresis threshold ใน Matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้:

  • ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
  • สร้าง figure และชุด subplots
  • โหลดเหรียญกรีก Greek coins from Pompeii
  • หา high, low และ edges ของภาพใช้ฟิลเตอร์ sobel
  • ใช้ hysteresis thresholding กับ "image"
  • แสดงข้อมูลเป็นภาพ คือ บน raster 2D ปกติ ใช้เมธอด imshow()
  • ตั้งค่า title สำหรับภาพต้นฉบับและภาพที่มี hysteresis threshold
  • เพื่อแสดงรูป ใช้เมธอด show()

ตัวอย่าง

import matplotlib.pyplot as plt
from skimage import data, filters

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

fig, ax = plt.subplots(nrows=1, ncols=2)
orig_img = data.coins()
edges = filters.sobel(orig_img)
low = 0.1
high = 0.4
low = (edges > low).astype(int)
height = (edges > high).astype(int)
hyst = filters.apply_hysteresis_threshold(edges, low, high)

ax[0].imshow(height + hyst, cmap='magma')
ax[0].set_xlabel('Hysteresis threshold')
ax[1].imshow(orig_img, cmap='magma')
ax[1].set_xlabel('Original Image')
plt.show()

ผลลัพธ์

วิธีพลอต Hysteresis Threshold ใน Matplotlib