[英]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.