I want to create an image out of an csv data.
I am reading the csv with:
f = open('file.csv', 'rb')
reader = csv.reader(f)
From here, I want to make a grayscale image that is translating each row of numbers in the list into a line of intensities in an image file.
Not sure what would be useful but here are some details about my csv file: using floats, columns:315, rows: 144
Thanks
Two steps:
From @Andrew on How to read csv into record array in numpy?
from numpy import genfromtxt
my_data = genfromtxt('my_file.csv', delimiter=',')
from numpy import genfromtxt
from matplotlib import pyplot
from matplotlib.image import imread
my_data = genfromtxt('path to csv', delimiter=',')
matplotlib.image.imsave('path to save image as Ex: output.png', my_data, cmap='gray')
image_1 = imread('path to read image as Ex: output.png')
# plot raw pixel data
pyplot.imshow(image_1)
# show the figure
pyplot.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With