카테고리 없음

[I2S] image resize에 관한

ML.chang 2020. 9. 25. 17:49

Resize images to size using the specified method.

Resized images will be distorted if their original aspect ratio is not the same as size. To avoid distortions see tf.image.resize_with_pad.

 

https://www.tensorflow.org/api_docs/python/tf/image/resize

 

tf.image.resize  |  TensorFlow Core v2.3.0

Resize images to size using the specified method.

www.tensorflow.org

image = tf.image.resize(image, (target_size, target_size))

을 하기 전

 

 

원본 shape=(300, 300, 3), dtype=uint8)

한 후 

reszie한것 shape=(300, 300, 3), dtype=float32

Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).

 

똑같이 300,300,3인데 하기 전이 훨씬 선명하다. float32이기 때문인것 같다. 255로 나눠주니까 선명하게  잘 나왔다. 

shape=(224, 224, 3), dtype=float32)

resize를 하면. matrix가 resize되며 성분값이 감소하며 재 배치?된다 .  1-->0.78125  이런식으로 줄어드는식 아래 코드 예시를 보면 이해가 갈 것이다. 

image = tf.constant([
 [1,0,0,0,0],
 [0,1,0,0,0],
 [0,0,1,0,0],
 [0,0,0,1,0],
 [0,0,0,0,1],
])
# Add "batch" and "channels" dimensions
image = image[tf.newaxis, ..., tf.newaxis]
image[0,...,0]
image.shape.as_list()  # [batch, height, width, channels]
print('\n')
tf.image.resize(image, [4,4])[0,...,0].numpy()
tf.image.resize(image, [4,4])[0,...,0].numpy().shape
print('\n')
tf.image.resize(image, [4,4]).numpy()

 

결론 분자 이미지를 (300,300)으로 생성해서 (299,299)나 (224,224) (128,128) 로 resize하는것이 문제가 없어 보인다. 

애초에 이미지 사이즈를 사전훈련된 모델에 넣기 위해서 맞추서 생성하면 어떨까 했는데 딱히 resize를 한다고 해서 문제가 생기진 않을 것 같다.