title: Convert JPG,PNG etc formats to PGM and make an array: Python
body: <p>I am converting .pgm images to array using below function. But right now i got all formats of images like .jpg/png etc. now i want to convert everything to .pgm (without savings) and needs to convert to array. i am using below function to convert into arrays</p>
  
  <pre><code>def image_array(pgm):
      pic = image.load_img(pgm, target_size=(224, 224))
      x = image.img_to_array(pic)
      x = np.expand_dims(x, axis=0)
      x = preprocess_input(x)
      npfeatures = np.array(x)
      return npfeatures
  </code></pre>
  
  <p>I tried below methods but couldnt integrate these things to above function.</p>
  
  <pre><code>image = cv2.imread('C:/Users/N/Desktop/Test.jpg')
  gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  </code></pre>
  
  <p>imports i used </p>
  
  <ul>
  <li>from keras.preprocessing import image</li>
  <li>from keras.applications.vgg16 import preprocess_input</li>
  <li>import cv2</li>
  </ul>