1

I'm using the MRI Preprocessed Dataset from Kaggle for my CNN project. This dataset contains .jpg images with dimensions of 128 x 128 pixels. In some references, this dataset is used with an image_size declaration of 224 x 224 pixels. How is the method used by TensorFlow for this resizing possible to implement? Can TensorFlow detect the color of a certain pixel and divide it into several pixels independently?

batch_size = 32
img_height = 224
img_width = 224

from tensorflow.keras.utils import image_dataset_from_directory
from tensorflow.keras.utils import image_dataset_from_directory

train_data = image_dataset_from_directory(
                  data_dir,
                  validation_split=0.2,
                  subset="training",
                  seed=123,
                  image_size=(img_height, img_width),
                  batch_size=batch_size)


val_data = image_dataset_from_directory(data_dir,
                                        validation_split=0.2,
                                        subset="validation",
                                        seed=123,
                                        image_size=(img_height,img_width),
                                        batch_size=batch_size)

I have used this code and the program can still run even though the image used has a size of 128 x 128 pixels. The program can still run and you see some changes when the img_height and img_width are changed between 128 x 128 and 224 x 224 pixels, so I think in this block of code the image size change occurs.

2 Answers2

1

There are upscale and downscale methods with different interpolation strategies.
https://chadrick-kwag.net/cv2-resize-interpolation-methods/

Tensorflow has similar options
https://www.tensorflow.org/api_docs/python/tf/image/resize

It really depends on what you need, but I usually do resizing based on this answer
https://stackoverflow.com/a/51042104/2083845

When you upscale an image, this of course won't do any magical details appear like in CSI. It will be somewhat blurry.

balazon
  • 76
  • 7
0

The parameter image_size does this:

image_size : Size to resize images to after they are read from disk, specified as (height, width). Defaults to (256, 256). Since the pipeline processes batches of images that must all have the same size, this must be provided.

from the tensorflow documentation

there are even more parameters, which you can set to resize the images diffrently.

I don't know which algorithm they use for scaling but it is likely one of these three:

  • nearest neighbor interpolation
  • bilinear interpolation
  • bicubic interpolation
Anton
  • 563
  • 4
  • 13