This beach
can be properly imported, resized and displayed with this code:
from tensorflow.keras.preprocessing.image import load_img, img_to_array
img_rows, img_cols = 32, 32
imgTest = load_img('beach.png', color_mode='grayscale', target_size=(img_rows, img_cols))
imgTest = img_to_array(imgTest) #returns a 3d numpy array
print(imgTest.shape)
imgTest=imgTest.squeeze()
plt.imshow(imgTest)
The numpy array has dimensions (32,32,1) so I have to drop the third dimension for it to properly display and that is why I use imgTest=imgTest.squeeze()
But the output is colorful even tho I converted to grayscale and my array is only 32x32 of luminance values. I would have thought the grayscale conversion would have remained gray.
Why are colors being shown?
If I use a grayscale image to start with like this one:
I get the same greenish 32x32 image. The array given by load_img has single luminance values, so where do the colors come from?
If I load the grayscale image WITHOUT grayscale conversion using:
imgTest = load_img('beachGRAY.png', target_size=(img_rows, img_cols))
and of course omit the squeeze statement because my array has RGB values, I get this warning:
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
and a blank plot. Why is my plot blank? When I look at print(imgTest[0:2]) There are numbers in there <255 so something should show. No?

