[์ฝ์ง tip] matplotlib.imshow()
matplotlib.imshow()
์ง๋ฌธ์์ ๋์์ต๋๋ค.. ์ type ์ ๋ณ๊ฒฝํ๋ฉด 255.0 ์ผ๋ก ๋๋์ด ์ฃผ๋ ์์ (normalize) ๊ฐ ํ์ํ ๊ฒ์ผ๊น์?
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
์ฝ๋๋ก ์ง์ ๊ตฌํํ์ ๋, โimshowโ๋ผ๋ ๋ฉ์๋๋ RGB data๋ก float type์ผ ๋, [0, 1] / int type์ผ ๋, [0, 255] ๋ผ๋ ์กฐ๊ฑด์ ๊ฐ์ง ๋์๋ง ์ ๋๋ก ๋ ์ด๋ฏธ์ง๋ฅผ ๋ณด์ฌ์ง๋ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค.
imshow๊ฐ matplotlib์์ ๊ฐ์ ธ์จ ๊ฒ์ธ๋ฐ,, ๋ณด๋๊น matplotlib์ ํน์ง์ธ ๊ฒ ๊ฐ์ต๋๋ค.
import sys
coco = COCO("../input/data/train.json")
image_id = coco.getImgIds(imgIds=0)
image_infos = coco.loadImgs(image_id)[0]
dataset_path_1 = '../input/data/'
images = cv2.imread(os.path.join(dataset_path_1, image_infos['file_name']))
plt.imshow(images)
#print(images)
fig, ax = plt.subplots(1, 3, figsize=(15, 5), sharey=True)
images_1 = cv2.cvtColor(images, cv2.COLOR_BGR2RGB).astype(np.int32)
ax[0].imshow(images_1, aspect="auto")
images_2 = cv2.cvtColor(images, cv2.COLOR_BGR2RGB).astype(np.float32)
ax[1].imshow(images_2, aspect="auto")
images_3 = cv2.cvtColor(images, cv2.COLOR_BGR2RGB).astype(np.float32)
images_3 /= 255.0
ax[2].imshow(images_3, aspect="auto")
plt.show()