0
votes

Suppose I have some image located at img_path. The code is then as follows:

from keras.preprocessing import image
import numpy as np

img = image.load_img(img_path, target_size=(150,150))
img_tensor = image.img_to_array(img)

When I print img_tensor I get the following:

array([[[164., 174., 186.],
        [161., 171., 183.],
        [161., 170., 185.],
        ...,
        [198., 214., 240.],
        [200., 216., 242.],
        [200., 216., 242.]],

       [[160., 170., 182.],
        [157., 167., 179.],
        [158., 167., 182.],
        ...,
        [199., 215., 241.],
        [201., 217., 243.],
        [201., 217., 243.]],

       [[161., 171., 183.],
        [159., 169., 181.],
        [160., 169., 184.],
        ...,
        [199., 215., 241.],
        [199., 215., 241.],
        [199., 215., 241.]],

The array obviously continues and at the end it says dtype=float32.

I know that the dimensions are 150x150x3. So my guess is that each bracketed bit written as, for example, [50., 50., 50.] is an individual pixel over the three channels for red green and blue. So R is at 50 (of the possible 255 being the maximum for red).

Then when it closes with the double brackets we've completed a row of pixels.

Is my intuition correct?

1
Yes, it's correctHa Bom
@Georgy I saw that post. What confused me was that the values were scaled differently from what I was looking at. I believe that what he was showing was the scaled values. I.e., the values I see divided by 255.Nicklovn

1 Answers

0
votes

Yes, your intuition is absolutely correct. The multi-dimensional array is the RGB representation of all the pixels in the image.