[Image-SIG] how to read tif image
Nadav Horesh
nadavh at visionsense.com
Mon Oct 22 12:30:52 CEST 2007
The 16 bit mode in not supported well (or not at all) via the array interface, so way I use it is via the good old buffer/string interface:
>>> from numpy import *
>>> import Image
>>> a = arange(65536, dtype=uint16).reshape(256, 256)
>>> a.shape
(256, 256)
>>> ima = Image.frombuffer('I;16', [256,256], a.data)
Warning (from warnings module):
File "__main__", line 1
RuntimeWarning: the frombuffer defaults may change in a future release; for portability, change the call to read:
frombuffer(mode, size, data, 'raw', mode, 0, 1)
>>> ima.save('16bits.tif')
>>> imb = Image.open('16bits.tif')
>>> stb = imb.tostring()
>>> len(stb)
131072
>>> b = fromstring(stb, dtype=uint16).reshape(256, 256)
>>> b.max()
65535
-----Original Message-----
From: B.R.ten_Broeke at lumc.nl [mailto:B.R.ten_Broeke at lumc.nl]
Sent: Mon 22-Oct-07 08:54
To: Nadav Horesh
Subject: RE: [Image-SIG] how to read tif image
How did you read the Images?
Bradley
-----Oorspronkelijk bericht-----
Van: Nadav Horesh [mailto:nadavh at visionsense.com]
Verzonden: Monday, October 22, 2007 7:59 AM
Aan: W. Bryan Smith; Broeke, B.R. ten (LKEB)
CC: Image-SIG at python.org
Onderwerp: RE: [Image-SIG] how to read tif image
I did use PIL to read/write 16 bit images (could be also 32 bits, but I
am not sure)
Nadav.
-----Original Message-----
From: image-sig-bounces at python.org on behalf of W. Bryan Smith
Sent: Wed 17-Oct-07 16:45
To: B.R.ten_Broeke at lumc.nl
Cc: Image-SIG at python.org
Subject: Re: [Image-SIG] how to read tif image
if i remember correctly, pil doesn't deal with 16-bit tif. i think
there
was a patch
around or something.... anyone have the info on this? tif does have a
very
specific header, including an offset (in bytes) to the image pixels, so
it
should
be pretty easy to use a binary read operation to get your pixels.
On 10/11/07, B.R.ten_Broeke at lumc.nl <B.R.ten_Broeke at lumc.nl> wrote:
>
> Hello,
>
>
>
> How do I read a (I;16) TIFF image with PIL?
>
> If I use the basic code:
>
> im = Image.open("file.tif")
>
> im.show()
>
> My output is a white screen. If I open the image with ImageJ, I have
no
> problems.
>
>
>
> Any suggestions?
>
> Thanx in advance.
>
>
>
> Bradley
>
> _______________________________________________
> Image-SIG maillist - Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
>
More information about the Image-SIG
mailing list