title: How to save 2D float numpy arrays losslessly into a grayscale image while preserving resolution?
body: <p>I have some Temperature field values which I want to convert to grayscale Image while <strong>preserving the resolution</strong>. (For example, if it's a (100x100) size float array, then the conversion should be a grayscale (100x100) image).Then I will process the image and convert it back to Temperature numpy array. The image processing part can be considered as a black-box process. </p>
  
  <p>It's important that the conversion is <strong>lossless</strong>. </p>
  
  <p>Also, the code for the image processing will recognise .png &amp; .jpg. ( I am not sure about recognition of other file formats including tiff. Also, even jpg formats are not preferred since they will result in lossy conversion). </p>
  
  <p>My attempts so far:</p>
  
  <ul>
  <li><p>Matplotlib's <code>imsave()</code> is resolution preserving and is lossless. But it converts the image into RGB instead of grayscale. This approach is also fine with me, but I am unable to accurately convert the 3 channel RGB image back to float numpy array. For example, I took a 10x10 numpy float array <code>temperature</code>, used <code>plt.imsave('Temperature_profile.png',temperature)</code>. Then, I reopened the same image but am unable to find out an accurate way to transform it back to (10x10) float array. So, the problem is solved if there is a way to convert back 3 channel image to 2D matrix losslessly.</p></li>
  <li><p>PIL's <code>Image.fromarray()</code> preserves resolution and can save image as a grayscale image. But I unable to save the matrix losslessly and retrieve it back losslessly. Hence I will get wrong results. (<a href="https://stackoverflow.com/questions/37558523/converting-2d-numpy-array-of-grayscale-values-to-a-pil-image/47598847#47598847">Converting 2D Numpy array of grayscale values to a PIL image</a>)</p></li>
  <li><p><code>scipy.misc.imsave()</code> has deprecated.</p></li>
  <li><p><code>imageio.imwrite()</code> gives a warning about lossy conversion. ("Lossy conversion from float64 to uint8"). </p></li>
  <li><p><code>opencv</code> and <code>cv2</code> for some reason is not getting recognised by my spyder environment (python 3.7,Anaconda 4.7.12).</p></li>
  </ul>