misc.imread를 사용하여 이미지를 Red, Green 및 Blue 채널로 분할하려면 다음 단계를 수행할 수 있습니다. -
- 그림 크기를 설정하고 서브플롯 사이 및 주변 여백을 조정합니다.
- 파일에서 배열로 이미지를 읽습니다.
- 컬러맵 및 제목 목록을 만듭니다.
- 그림과 서브플롯 세트를 생성합니다.
- 축, 이미지, 제목 및 컬러맵을 압축합니다.
- 압축된 objs를 반복하고 각 채널 이미지의 제목을 설정합니다.
- 그림을 표시하려면 show()를 사용하세요. 방법.
예시
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
image = plt.imread('bird.png')
titles = ['With red channel', 'With green channel', 'With blue channel']
cmaps = [plt.cm.Reds_r, plt.cm.Greens_r, plt.cm.Blues_r]
fig, axes = plt.subplots(1, 3)
objs = zip(axes, (image, *image.transpose(2, 0, 1)), titles, cmaps)
for ax, channel, title, cmap in objs:
ax.imshow(channel, cmap=cmap)
ax.set_title(title)
ax.set_xticks(())
ax.set_yticks(())
plt.show() 입력 이미지

출력 이미지
