0

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:

  1. How do I import all the 500 images at a time into python and how do i store it?
  2. How do I send the 500 pixel list via COM1 to FPGA?

I tried the following:

  1. 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!
  2. 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! :)

Kiran
20.3k11 gold badges72 silver badges101 bronze badges
asked Mar 20, 2012 at 16:45

1 Answer 1

3

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.

answered Mar 20, 2012 at 17:20
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Martin. That was very helpful. Can you tell me a way to import more than one image at a time. Like, sort of GUI in which I can select more than one image by pressing "Ctrl" and then clicking OK will select all the images and import them into a matrix in python. Lets say, I want to import 10 grey scale images.. I open the GUI, select 10 images and then after clicking okay, I should be able to get a matrix of dimensions row*col*10. Can you please help me how to do it? I couldnt figure out myself.. Thank you in advance :) s-elektron
and one more small correction.. it should be: pixel = im.getpixel((0,0)) i suppose.. im.getpixel(0,0) was not working in Python 2.6. I haven't tried in other versions though

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.