How to convert image to csv?

I’ve done the image editing but can’t seem to undestand how to convert that image to a csv file. Need help with that.

Hey @nishanttaneja,
If you edited the image correctly, you must be having an Image Array with shape=(430,430,3).
You should follow the following steps:

  1. Convert the Image array to a numpy array.
    array=np.array(array)
  2. Reshape the array
    array=array.reshape(430*430,3)
    This will reshape your array into size = (184900,3).
  3. Use np.savetxt to convert the array to csv.
    np.savetxt(file_name='abc.csv',array=array,fmt="%d",header="R,G,B")

I hope this helps!

1 Like