Raw images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tuvas

    #1

    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!

  • Peter Hansen

    #2
    Re: Raw images

    Tuvas wrote:[color=blue]
    > 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![/color]

    Assuming the numbers are stored as bytes in a file, this should work
    using PIL at http://www.pythonware.com/products/pil/
    [color=blue][color=green][color=darkred]
    >>> import Image
    >>> bytes = open('myfile', 'rb').read()
    >>> y = Image.fromstrin g('L', (xsize, ysize), x)
    >>> y.save('test.pn g', 'PNG')[/color][/color][/color]

    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

    Comment

    • Tuvas

      #3
      Re: Raw images

      That will definatly help. Thanks!

      Comment

      • Bryan Olson

        #4
        Re: Raw images

        Tuvas wrote:[color=blue]
        > I have an image that is in a "raw" format, ei, no place markers to tell
        > the dimensions, just a big group of numbers.[/color]

        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".
        [color=blue]
        > 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.[/color]

        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:




        --
        --Bryan

        Comment

        • Tuvas

          #5
          Re: Raw images

          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.

          Comment

          • Paul Rubin

            #6
            Re: Raw images

            "Tuvas" <tuvas21@gmail. com> writes:[color=blue]
            > I have an image that is in a "raw" format,[/color]

            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.

            Comment

            • Tuvas

              #7
              Re: Raw images

              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.fromstrin g('L', (xsize, ysize), data) to create image
              5.Use
              im.thumbnail((7 00,700))
              image=ImageTk.B itmapImage(im)
              pic=canvas.crea te_image(1,1,an chor="nw",image =image,tag="pic ")
              canvas.addtag_w ithtag("pic",pi c)

              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!

              Comment

              • Fredrik Lundh

                #8
                Re: Raw images

                "Tuvas" wrote:
                [color=blue]
                > 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.fromstrin g('L', (xsize, ysize), data) to create image[/color]

                PIL can do this conversion for you (by specifying a "raw mode" to
                fromstring). I'll post an example later.
                [color=blue]
                > image=ImageTk.B itmapImage(im)
                > pic=canvas.crea te_image(1,1,an chor="nw",image =image,tag="pic ")
                > canvas.addtag_w ithtag("pic",pi c)
                >
                > 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?[/color]

                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:



                </F>



                Comment

                • Tuvas

                  #9
                  Re: Raw images

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

                  Comment

                  Working...