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:
- How do I import all the 500 images at a time into python and how do i store it?
- How do I send the 500 pixel list via COM1 to FPGA?
I tried the following:
- Converted the jpeg image to intensity values (each pixel is denoted by a number between 0 and 255) in MATLAB, saved the intensity values in a text file, read that file using
readlines(). But it became too cumbersome to make the intensity value files for all the 500 images! - Used NumPy to put the read files in a matrix and then pick the first pixel of all images. But when I send it, its coming like:
[56, 61, 78, ... ,71, 91].
Is there a way to eliminate the [ ] and , while sending the data serially?
Thanks in Advance! :)
1 Answer 1
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.