Raw images

T

Tuvas

I have an image that is in a "raw" format, ei, no place markers to tell
the dimensions, just a big group of numbers. I happen to know the
dimension of this array from a different source. I would like to be
able to display it. Is there a way to do this easily? I know that
several libraries use a "raw" function, but I have little doubt that
this differs somewhat from program to program. Thanks!
 
P

Peter Hansen

Tuvas said:
I have an image that is in a "raw" format, ei, no place markers to tell
the dimensions, just a big group of numbers. I happen to know the
dimension of this array from a different source. I would like to be
able to display it. Is there a way to do this easily? I know that
several libraries use a "raw" function, but I have little doubt that
this differs somewhat from program to program. Thanks!

Assuming the numbers are stored as bytes in a file, this should work
using PIL at http://www.pythonware.com/products/pil/

The 'L' in the above is for bytes, and this obviously saves the image as
a PNG file. Lots of variation in the above is possible but your specs
are fairly wide open so it's up to you to experiment and then maybe
clarify your specs.

-Peter
 
B

Bryan Olson

Tuvas said:
> I have an image that is in a "raw" format, ei, no place markers to tell
> the dimensions, just a big group of numbers.

The adjective "raw", apt as it may be, is a long way from specifying
the representation of an image. *Every* digital format is "just a big
group of numbers".
> I happen to know the
> dimension of this array from a different source. I would like to be
> able to display it. Is there a way to do this easily? I know that
> several libraries use a "raw" function, but I have little doubt that
> this differs somewhat from program to program.

Well, maybe it's easy. Perhaps a straightforward interpretation of the
numbers, along with the dimensions you know, will yield the image. It
might be harder. For an arguably-overstated exposition, see:

http://luminous-landscape.com/essays/raw-law.shtml
 
T

Tuvas

Well, the numbers are in a string of variable length. My camera can
read specific parts of it's display, so an image of 1024x1024 is just
as likely to happen as one of 16x342. Well, not really, but they both
could happen. The data is passed by giving the dimentions via a
seperate protocol, and then passing the numbers. I've converted the
passed numbers to a list of integers. Each is a 16 bit number, BTW. I
just needed to display that in a fixed size box, and the answer that
was giving using PIL will work perfectly.
 
P

Paul Rubin

Tuvas said:
I have an image that is in a "raw" format,

Do you mean a RAW file from a digital camera? Those files have
complex and sometimes secret formats. Google "dcraw.c" for a decoding
program that works for many cameras.
 
T

Tuvas

Well, it's a custum-built camera, so it's not standard by any means.
That being the case, I know it's exact format, which is as follows. It
is a stream of 16 bit numbers, each representing a point on a grid. The
grid is define in a seporate way, outside of the format, but is given a
number of rows and columns. From these, an image is defined. I simply
need to take this stream, which I converted to a giant string, and
display it in the form of a picture. What I've tried to do is as
follows:

1. Read string
2. Form an array by combining 2 chars together.
3. Divide by 256 so as to have a 8 bit number, which PIL likes alot
better than a 16 bit number. The string is called data.
4. Use im = Image.fromstring('L', (xsize, ysize), data) to create image
5.Use
im.thumbnail((700,700))
image=ImageTk.BitmapImage(im)
pic=canvas.create_image(1,1,anchor="nw",image=image,tag="pic")
canvas.addtag_withtag("pic",pic)

There seems to be a problem with the last line, but no picture is
displayed without it. That isn't related to the problem I'm having, but
I also need to fix it. The problem is it won't display the image, it
seems to display nothing. Any ideas as to why? I've tried using
PhotoImage, with the same result. Perhaps it's the thumbnail command, I
don't know if it has problems if you try to make a thumbnail larger
than the picture, but I would presume there's a way around this. Ideas?
Thanks!
 
F

Fredrik Lundh

Tuvas said:
1. Read string
2. Form an array by combining 2 chars together.
3. Divide by 256 so as to have a 8 bit number, which PIL likes alot
better than a 16 bit number. The string is called data.
4. Use im = Image.fromstring('L', (xsize, ysize), data) to create image

PIL can do this conversion for you (by specifying a "raw mode" to
fromstring). I'll post an example later.
image=ImageTk.BitmapImage(im)
pic=canvas.create_image(1,1,anchor="nw",image=image,tag="pic")
canvas.addtag_withtag("pic",pic)

There seems to be a problem with the last line, but no picture is
displayed without it. That isn't related to the problem I'm having, but
I also need to fix it. The problem is it won't display the image, it
seems to display nothing. Any ideas as to why?

if you have a grayscale image, you should use PhotoImage, not BitmapImage.

as for the disappearing image, see the note at the bottom of this page:

http://www.effbot.org/tkinterbook/photoimage.htm

</F>
 
T

Tuvas

That did the trick, I can now remove the bad tag statement, and it all
works just nicely. Thank you very much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,274
Messages
2,571,368
Members
48,060
Latest member
JerrodSimc

Latest Threads

Top