473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Raw images

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!

Dec 20 '05 #1
8 3668
Tuvas wrote:
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/
import Image
bytes = open('myfile', 'rb').read()
y = Image.fromstring('L', (xsize, ysize), x)
y.save('test.png', 'PNG')


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

Dec 20 '05 #2
That will definatly help. Thanks!

Dec 20 '05 #3
Tuvas wrote:
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
--
--Bryan
Dec 20 '05 #4
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.

Dec 20 '05 #5
"Tuvas" <tu*****@gmail.com> writes:
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.
Dec 20 '05 #6
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=imag e,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!

Dec 21 '05 #7
"Tuvas" wrote:
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=imag e,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>

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

Dec 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Wayne | last post by:
I have a script that uses filesystemobject that reads files from a given path, in my case images. It is running on a server that is 2000 adv svr w/ all current patches. The script prior to some...
3
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a...
10
by: Neo Geshel | last post by:
I am seeking to hand-roll my own blog in ASP.NET 2.0 and SQLExpress 2005. Why? Because I can. Because I will gain experience. The one thing that has me stumped at square one is inline images....
6
by: wattanabi | last post by:
Greetings, I'm attempting to layout a bunch of images in a grid using DIV's instead of a table. I currently have a 3x6 table that I need to convert to css. I've seen various example of a 3 to 4...
2
by: mouseit101 | last post by:
Hi, I'm writing a script that would (hopefully) search google images for whatever, and then return a list of URLs for the image. Right now I have: $dom = new DomDocument(); $url =...
0
by: Frenchie | last post by:
Hi, I have created a very neet menu from an example found on the MSDN library at: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.menuitembinding.imageurlfield.aspx My...
1
by: Cerebral Believer | last post by:
Hi folks, I am using the following code for mouse over (roll-overs) in my XHTML code. <a onmouseover="document.getElementById('sitemap').src = '../images/buttons/sitemap_mo.jpg';"...
4
toxicpaint
by: toxicpaint | last post by:
Hi, can anyone give me a hand. I'm currently displaying 4 random images at the top of a page. I did this using an array of 35 pictures and then writing them to page. The problem I have is that in...
5
by: remon87 | last post by:
I need some help. I have javasript that creates the submenu but it works if I have a text with css. I need it to do the same with a roll over images. so when I click on the image the submenu...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.