[英]Plotting positive and negative pixels of image separately on subplots
您可以將所有高於或低於某個閾值的值都設置為nan
,這樣它們就不會出現在最終圖像中。
以下代碼完全超出了0.4到0.6的范圍。 選擇黃色背景以顯示該區域中沒有像素。
import numpy as np
import matplotlib.pyplot as plt
img = plt.imread("grayscaleimage.png")[:,:,0]
white = np.copy(img)
white[white<0.6] = np.nan
dark = np.copy(img)
dark[dark>0.4] = np.nan
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax1 = fig.add_subplot(223)
ax2 = fig.add_subplot(224)
ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")
for ax in (ax1,ax2):
ax.set_facecolor("gold")
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.