머신러닝 아이디어/CT-Scan-Chest-Cancer

데이터 전처리 - 이미지

명징직조지훈 2022. 10. 20. 22:58

획득 이미지의 확인



각 이미지의 픽셀 크기는 제각각, CNN 모델에 넣기 전 각 이미지들의 픽셀 크기를 동일하게 만들어야 한다. 이러한 변환 ㄱ과정에서 각 이미지들이 가진 정보 손실을 최소화하기 위해 가장 큰 사이즈의 이미지의 크기로 동일하게 만들어준다.(다른 이미지 변환 방법 생각)

def biggest_image(image_list):
  height = int(image_list[0].shape[0])
  width = int(image_list[0].shape[1])

  for i in image_list:
    image_height = int(i.shape[0])
    image_width = int(i.shape[1])
    if height < image_height:
      height = image_height
    if width < image_width:
      width = image_width

  return height, width

각 분류들의 최대 너비, 높이 값을 획득할 수 있음, 해당 함수를 통해 모든 데이터들의 이미지 크기 변환

image_data = []

for i in data:
  image_data.append(tf.image.resize_with_crop_or_pad(i,height, width))

이미지의 변환을 확인할 수 있다.