Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!reader02.news.zen.co.uk.POSTED!not-for-mail From: Nobody Subject: Re: working with raw image files Date: Wed, 15 Jun 2011 02:33:46 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.lang.python References: <0cd64f09-bd32-4b67-9266-46003dbea4b7@m4g2000yqk.googlegroups.com> <1f7a452a-8bae-43e0-ab9f-9bfed55ee206@b21g2000yqc.googlegroups.com> <57d6da80-59db-477f-b507-cabf01a2976d@j23g2000yqc.googlegroups.com> <720bec5b-4892-4cd7-83e1-f67ce78591be@y30g2000yqb.googlegroups.com> <71140671-4273-417d-8d2f-3986663acdb2@k16g2000yqm.googlegroups.com> <2c095413-ea59-4339-8419-ae4b688e219d@17g2000prr.googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 25 Organization: Zen Internet NNTP-Posting-Host: 00e85a38.news.zen.co.uk X-Trace: DXC=;VjMJ4Ha?bk05G]jnOkg8gYjZGX^207Pk`l5a4fIdmNQ<`Sf8^Tao]n1]`k=YKkg X-Complaints-To: abuse@zen.co.uk Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7662 On Tue, 14 Jun 2011 13:13:07 -0700, kafooster wrote: > Ok, I solved the problem with matplotlib > > fileobj = open("hand.raw", 'rb') > data = numpy.fromfile(fileobj,dtype=np.uint16) > data = numpy.reshape(data,(96,470,352)) > imshow(data[:,:,40],cmap='gray') > show() > > the error was caused by different order of data, however it still > reads the dataset as half of it size. whatever. > > please leave the part about .raw, lets just start thinking of it from > level of numpy array. > > I would like to visualize this data with PIL, but PIL works only with > 8bit data. How could I resample my array from 16bit to 8bit? Why bother? NumPy is a much better image-processing library than PIL. The only reason I use PIL is for its import/export routines. If you are going to use PIL, apply any corrections (gamma correction, histogram equalisation, etc) before reducing the data to 8 bits.