๋ฐ์ํ
def img_show(title='image', img=None, figsize=(8 ,5)):
plt.figure(figsize=figsize)
if type(img) == list:
if type(title) == list:
titles = title
else:
titles = []
for i in range(len(img)):
titles.append(title)
for i in range(len(img)):
if len(img[i].shape) <= 2:
rgbImg = cv2.cvtColor(img[i], cv2.COLOR_GRAY2RGB)
else:
rgbImg = cv2.cvtColor(img[i], cv2.COLOR_BGR2RGB)
plt.subplot(1, len(img), i + 1), plt.imshow(rgbImg)
plt.title(titles[i])
plt.xticks([]), plt.yticks([])
plt.show()
else:
if len(img.shape) < 3:
rgbImg = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
else:
rgbImg = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(rgbImg)
plt.title(title)
plt.xticks([]), plt.yticks([])
plt.show()
์ฃผํผํฐ ๋ ธํธ๋ถ ํ๊ฒฝ์์ ์ ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์๋์ ๊ฐ์ด (์ด๋ฏธ์ง ํ์ดํ ๋ฆฌ์คํธ, ์ด๋ฏธ์ง ๋ฆฌ์คํธ)๋ฅผ ํจ๊ป ํด๋น ํจ์์ ๋ฃ์ด์ฃผ๋ฉด ์ด๋ฏธ์ง ์ถ๋ ฅ ๊ฐ๋ฅ. ์ฃผํผํฐ ๋ ธํธ๋ถ ํ๊ฒฝ์์ ์ฌ๋ฌ๊ฐ์ง ํ ์คํธํ๊ณ ๊ฐ๋จํ ๋น๊ตํด๋ณด๊ณ ํ ๋ ์ ์ฉํ๋ค.
๋ฐ์ํ