Reputation: 52
I have an image stack of 500 images (jpeg) of 640x480. I intend to make 500 pixels (1st pixels of all images) as a list and then send that via COM1 to FPGA where I do my further processing.
I have a couple of questions here:
I tried the following:
readlines()
. But it became too cumbersome to make the intensity value files for all the 500 images![56, 61, 78, ... ,71, 91]
.Is there a way to eliminate the [ ]
and ,
while sending the data serially?
Thanks in Advance! :)
Upvotes: 0
Views: 1038
Reputation: 29164
Ad 1: Use a library like PIL for accessing the images. You can load an image using
from PIL import Image
im = Image.open("img000.jpg")
And access the first pixel value using
pixel = im.getpixel(0,0)
This returns a color tuple for the first pixel, you have to calculate the intensity from this.
Ad 2: This depends on how your FPGS expects the values? Since you mentioned eliminating [
, do you need a comma-separated ASCII string? Try
pixel_string = ','.join([str(x) for x in pixel_list])
If you need to send a series of bytes construct the byte string like
pixel_string = ''.join([chr(x) for x in pixel_list])
Both examples assume, that you have constructed you list of intensity values in pixel_list
.
Upvotes: 3