๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป Programming/Computer Vision

[python] ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ ํ™˜๊ฒฝ์—์„œ ์ด๋ฏธ์ง€ ์ถœ๋ ฅํ•˜๊ธฐ ํŒ

by ๋ญ…์ฆค 2022. 10. 31.
๋ฐ˜์‘ํ˜•
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()

์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ ํ™˜๊ฒฝ์—์„œ ์œ„ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•„๋ž˜์™€ ๊ฐ™์ด (์ด๋ฏธ์ง€ ํƒ€์ดํ‹€ ๋ฆฌ์ŠคํŠธ, ์ด๋ฏธ์ง€ ๋ฆฌ์ŠคํŠธ)๋ฅผ ํ•จ๊ป˜ ํ•ด๋‹น ํ•จ์ˆ˜์— ๋„ฃ์–ด์ฃผ๋ฉด ์ด๋ฏธ์ง€ ์ถœ๋ ฅ ๊ฐ€๋Šฅ. ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ ํ™˜๊ฒฝ์—์„œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ํ…Œ์ŠคํŠธํ•˜๊ณ  ๊ฐ„๋‹จํžˆ ๋น„๊ตํ•ด๋ณด๊ณ  ํ•  ๋•Œ ์œ ์šฉํ•˜๋‹ค.

 

๋ฐ˜์‘ํ˜•