title: reading images with matplotlib
body: <p>So I was playing with : <a href="http://scikit-learn.org/stable/auto_examples/classification/plot_digits_classification.html#example-classification-plot-digits-classification-py" rel="nofollow noreferrer">http://scikit-learn.org/stable/auto_examples/classification/plot_digits_classification.html#example-classification-plot-digits-classification-py</a></p>
  <p>And I tried to load an image from my disk, I drawed a number in a 8x8 png image using paint.</p>
  <p>the scikit-learn images look like that :</p>
  <pre><code>[[  0.   0.   5.  13.   9.   1.   0.   0.]
   [  0.   0.  13.  15.  10.  15.   5.   0.]
   [  0.   3.  15.   2.   0.  11.   8.   0.]
   [  0.   4.  12.   0.   0.   8.   8.   0.]
   [  0.   5.   8.   0.   0.   9.   8.   0.]
   [  0.   4.  11.   0.   1.  12.   7.   0.]
   [  0.   2.  14.   5.  10.  12.   0.   0.]
   [  0.   0.   6.  13.  10.   0.   0.   0.]]
  </code></pre>
  <p>where 0 is white and the grater the value the darker the pixel is.
  When I load an image I get this :</p>
  <pre><code>[[[ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 0.85882354  0.85882354  0.85882354]
    [ 0.14901961  0.14901961  0.14901961]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]]
  
   [[ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 0.56862748  0.56862748  0.56862748]
    [ 0.22745098  0.22745098  0.22745098]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]]
  
   [[ 1.          1.          1.        ]
    [ 0.9254902   0.9254902   0.9254902 ]
    [ 0.13725491  0.13725491  0.13725491]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]]
  
   [[ 1.          1.          1.        ]
    [ 0.53725493  0.53725493  0.53725493]
    [ 0.63137257  0.63137257  0.63137257]
    [ 0.62352943  0.62352943  0.62352943]
    [ 0.97254902  0.97254902  0.97254902]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]]
  
   [[ 1.          1.          1.        ]
    [ 0.36078432  0.36078432  0.36078432]
    [ 0.18431373  0.18431373  0.18431373]
    [ 0.72941178  0.72941178  0.72941178]
    [ 0.07843138  0.07843138  0.07843138]
    [ 0.86274511  0.86274511  0.86274511]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]]
  
   [[ 1.          1.          1.        ]
    [ 0.29411766  0.29411766  0.29411766]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 0.42352942  0.42352942  0.42352942]
    [ 0.80000001  0.80000001  0.80000001]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]]
  
   [[ 1.          1.          1.        ]
    [ 0.19607843  0.19607843  0.19607843]
    [ 0.96470588  0.96470588  0.96470588]
    [ 0.90980393  0.90980393  0.90980393]
    [ 0.08627451  0.08627451  0.08627451]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]]
  
   [[ 1.          1.          1.        ]
    [ 0.96862745  0.96862745  0.96862745]
    [ 0.28627452  0.28627452  0.28627452]
    [ 0.35686275  0.35686275  0.35686275]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]
    [ 1.          1.          1.        ]]]
  </code></pre>
  <p>Is there a built in function to convert it in a format similar to scikit-learn images? or should I write my own convertion function?</p>
  <p>Could someone explain what imread output means? I have 8 8x3 2D arrays, I can't figure out what it is.</p>
  <p>the documentation says that is MxN but I don't know what MxN means. <a href="http://matplotlib.org/api/image_api.html#matplotlib.image.imread" rel="nofollow noreferrer">http://matplotlib.org/api/image_api.html#matplotlib.image.imread</a></p>
  <p>Thanks</p>
  <h1>EDIT</h1>
  <p>so this is the code I made thanks to ali_m</p>
  <pre><code>from numpy import array
  
  def loadImageFromDisk(image_path):
  
      def convertImreadImage(img):
          &quot;&quot;&quot;
          Convert imread images to scikit-learn images
              -img : a 2 dimension array (regular or numpy array)
              -return : a 2 dimension numpy array where 0 is white and
                        the higher the value the darker the pixel
          &quot;&quot;&quot;
          res = []
          for row in img:
              newRow = []
              for value in row:
                  if value == 1.:
                      newRow.append(0)
                  else:
                      newRow.append(math.floor((100-value*100)/5))
              res.append(newRow)
          return array(res)
  
      #needs to be a absolute path
      img = mpimg.imread(image_path)[:, :, 0]
      return convertImreadImage(img)
  </code></pre>
  <p>output for a 6 in a 8x8 png file :</p>
  <pre><code>[[  0.   0.   0.   2.  19.   0.   0.   0.]
   [  0.   0.   2.  20.  13.   0.   0.   0.]
   [  0.   1.  20.  16.   0.   0.   0.   0.]
   [  0.  15.  20.  20.  16.   3.   0.   0.]
   [  0.  20.  20.   1.  18.  20.   0.   0.]
   [  0.  20.   9.   0.   1.  20.   0.   0.]
   [  0.  20.   9.   2.  17.  18.   0.   0.]
   [  0.   6.  20.  20.  19.   0.   0.   0.]]
  </code></pre>