Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7555
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'skip:# 20': 0.03; 'scipy': 0.05; 'int,': 0.07; 'pixel': 0.07; 'slice': 0.07; 'extension.': 0.09; 'from:addr:python': 0.09; 'header,': 0.09; 'subject:files': 0.09; 'subject:image': 0.09; 'pm,': 0.10; '>>>': 0.12; 'wrote:': 0.14; '"\\\\"': 0.16; "'rb')": 0.16; '2:18': 0.16; 'arrays.': 0.16; 'bit.': 0.16; 'data2': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'image1': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'numpy': 0.16; 'pylab': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr:python-list': 0.16; 'set,': 0.16; 'subject:raw': 0.16; 'simpler': 0.19; 'header:In- Reply-To:1': 0.21; 'set.': 0.23; 'values.': 0.23; 'worked': 0.24; 'code': 0.24; "doesn't": 0.25; 'checked': 0.25; 'like.': 0.25; 'received:84': 0.25; "i'm": 0.27; 'e.g.': 0.29; 'import': 0.29; 'skip:i 30': 0.29; 'bit': 0.30; 'array': 0.30; 'buffer,': 0.30; 'subject:working': 0.30; 'changes': 0.30; 'print': 0.31; 'to:addr :python-list': 0.33; 'file': 0.34; 'however,': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'reply-to:addr:python.org': 0.35; 'using': 0.35; 'data,': 0.36; 'open': 0.36; 'something': 0.37; 'change': 0.37; 'think': 0.38; 'could': 0.38; 'but': 0.38; 'data': 0.38; 'size,': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'printed': 0.39; 'subject:with': 0.39; 'to:addr:python.org': 0.39; 'really': 0.40; 'more': 0.60; 'medical': 0.65; 'here': 0.66; 'noise': 0.67; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'messed': 0.84; 'pro': 0.89; '8bit': 0.91; 'something.': 0.91 |
| X-IronPort-Anti-Spam-Filtered | true |
| X-IronPort-Anti-Spam-Result | AhMIAE909k1UXebj/2dsb2JhbABSmAqOJ3eIcr8vhiQElgOLDw |
| Date | Mon, 13 Jun 2011 21:36:01 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| 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> |
| In-Reply-To | <a4d759a7-02dd-47b9-ba38-0dc947561230@k16g2000yqm.googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | python-list@python.org |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.195.1307997358.11593.python-list@python.org> (permalink) |
| Lines | 80 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1307997359 news.xs4all.nl 49175 [::ffff:82.94.164.166]:58251 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:7555 |
Show key headers only | 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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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