Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7555

Re: working with raw image files

Date 2011-06-13 21:36 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: working with raw image files
References <0cd64f09-bd32-4b67-9266-46003dbea4b7@m4g2000yqk.googlegroups.com> <1f7a452a-8bae-43e0-ab9f-9bfed55ee206@b21g2000yqc.googlegroups.com> <a4d759a7-02dd-47b9-ba38-0dc947561230@k16g2000yqm.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.195.1307997358.11593.python-list@python.org> (permalink)

Show all headers | View raw


On 13/06/2011 21:20, Wanderer wrote:
> On Jun 13, 4:08 pm, Wanderer<wande...@dialup4less.com>  wrote:
>> On Jun 13, 2:18 pm, kafooster<dmoze...@gmail.com>  wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> I am working on some medical image data, and I try to look into
>>> specific slice of   3d  *.raw image. I know voxels are 16 bit int, and
>>> dimensions are 352*470*96. I checked it in some pro medical image
>>> viewer, it is alright. However, with the code I use, I display just
>>> white noise image.(but worked well for other, 8bit raw image).
>>>   Also, printed size is half the original size, like it was 8 bit. I
>>> read some documentations on PIL, numpy etc but I think I just do not
>>> understand something.
>>> I open image data set, I change it to array, give it dimensions,
>>> dtype, and change it to image, right? I think there is something
>>> messed up in 'binvalues', but dont really know how to write it in
>>> simpler way.
>>
>>> P.S.1
>>> If I want to change data type to e.g. 8 bit uint, is it just change in
>>> scipy.array? or it requires some more changes
>>
>>> P.S.2
>>> Lets say I have my array of image data and want to save it to *.raw
>>> data set. is it array.tofile?
>>
>>> Here is my code
>>
>>> ############################
>>
>>> import scipy as sc
>>> from pylab import *
>>> import array
>>> import Image
>>
>>> fileobj = open("hand.raw", 'rb')
>>> binvalues = array.array('B')
>>> binvalues.read (fileobj, 352*470*96)
>>> data1 = sc.array(binvalues, dtype=sc.int16)
>>> data2 = sc.reshape(data1, (352,470,96))
>>> fileobj.close()
>>> print data2.size , data2.dtype
>>
>>> im = Image.fromarray(data2[:,:,40])
>>> im.show()
>>
>> Try using numpy arrays.
>>
>> import numpy as np
>> import Image
>>
>> image1 = Image.open("hand.raw", 'rb')
>> imshape = image1.size
>> npArray = np.array(image1.getdata())
>> npArray.shape = imshape
>>
>> im = Image.fromarray(npArray)
>> im.show()
>
> P.S.1
> If you want to change data size from a data buffer, you could use
> something like.
>
>   image1 = np.frombuffer(Buffer, np.uint16)
>
> P.S.2
> I'm not sure what a *.raw file is but if Image has support for it you
> just need to include the extension.
>
>   im = Image.fromarray(npArray)
>   im.save(self.resultDir + "\\" + imageName + '.tif')
>
A .raw file doesn't contain a header, just the pixel values.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-13 11:18 -0700
  Re: working with raw image files Terry Reedy <tjreedy@udel.edu> - 2011-06-13 14:49 -0400
  Re: working with raw image files Wanderer <wanderer@dialup4less.com> - 2011-06-13 13:08 -0700
    Re: working with raw image files Wanderer <wanderer@dialup4less.com> - 2011-06-13 13:20 -0700
      Re: working with raw image files MRAB <python@mrabarnett.plus.com> - 2011-06-13 21:36 +0100
      Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-13 13:41 -0700
        Re: working with raw image files Wanderer <wanderer@dialup4less.com> - 2011-06-13 13:52 -0700
          Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-13 13:58 -0700
            Re: working with raw image files Wanderer <wanderer@dialup4less.com> - 2011-06-13 14:28 -0700
              Re: working with raw image files Martin De Kauwe <mdekauwe@gmail.com> - 2011-06-14 00:49 -0700
                Re: working with raw image files Terry Reedy <tjreedy@udel.edu> - 2011-06-14 12:24 -0400
                Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-14 13:13 -0700
                Re: working with raw image files MRAB <python@mrabarnett.plus.com> - 2011-06-14 21:26 +0100
                Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-14 14:20 -0700
                Re: working with raw image files MRAB <python@mrabarnett.plus.com> - 2011-06-14 23:06 +0100
                Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-14 16:59 -0700
                Re: working with raw image files MRAB <python@mrabarnett.plus.com> - 2011-06-15 01:24 +0100
                Re: working with raw image files Dave Angel <davea@ieee.org> - 2011-06-14 19:25 -0400
                Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-14 17:02 -0700
                Re: working with raw image files Dave Angel <davea@ieee.org> - 2011-06-14 22:13 -0400
                Re: working with raw image files Nobody <nobody@nowhere.com> - 2011-06-15 02:29 +0100
                Re: working with raw image files Nobody <nobody@nowhere.com> - 2011-06-15 02:33 +0100

csiph-web