PIL: TIFF images loaded as 16 bit signed integers

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

PIL: TIFF images loaded as 16 bit signed integers

Chris Mitchell-2
I'm running into a problem where my image intensities are being loaded
as 16 bit signed integers.  The code I'm using to open the tiff file
is:


im = Image.open(file)
self.pixels = np.array([im.getdata()], np.uint16)

the filetype is a 16bit TIFF, whose intensities load fine into ImageJ.
 I load their intensities into a numpy 16bit array, and for the time
being I've fixed this problem with this code:

np.where(self.pixels<0, -1*self.pixels+(32768+self.pixels),self.pixels)

That basically takes any negative values and compensates for the
rollover.  Does anyone have any idea why PIL is loading my TIFF files
as signed integers?
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: PIL: TIFF images loaded as 16 bit signed integers

Fredrik Lundh
2010/7/6 Chris Mitchell <[hidden email]>:

> I'm running into a problem where my image intensities are being loaded
> as 16 bit signed integers.  The code I'm using to open the tiff file
> is:
>
> im = Image.open(file)
> self.pixels = np.array([im.getdata()], np.uint16)
>
> the filetype is a 16bit TIFF, whose intensities load fine into ImageJ.
>  I load their intensities into a numpy 16bit array, and for the time
> being I've fixed this problem with this code:
>
> np.where(self.pixels<0, -1*self.pixels+(32768+self.pixels),self.pixels)
>
> That basically takes any negative values and compensates for the
> rollover.  Does anyone have any idea why PIL is loading my TIFF files
> as signed integers?

Could be that something goes wrong on the way to numpy.  What values
do you get from PIL's own access methods (e.g. getpixel)?

Also, what platform is this on?

</F>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: PIL: TIFF images loaded as 16 bit signed integers

Chris Mitchell-2
My platform is windows 7 64bit, and when I do this:

import Image
im = Image.open(file)
print im.getpixel((168,78)) #pixel intensity is 65535, gives -1 as value
print im.getpixel((169,78)) #pixel intensity is 64453, gives -1083 as value.


On Sun, Aug 1, 2010 at 7:14 AM, Fredrik Lundh <[hidden email]> wrote:

> 2010/7/6 Chris Mitchell <[hidden email]>:
>> I'm running into a problem where my image intensities are being loaded
>> as 16 bit signed integers.  The code I'm using to open the tiff file
>> is:
>>
>> im = Image.open(file)
>> self.pixels = np.array([im.getdata()], np.uint16)
>>
>> the filetype is a 16bit TIFF, whose intensities load fine into ImageJ.
>>  I load their intensities into a numpy 16bit array, and for the time
>> being I've fixed this problem with this code:
>>
>> np.where(self.pixels<0, -1*self.pixels+(32768+self.pixels),self.pixels)
>>
>> That basically takes any negative values and compensates for the
>> rollover.  Does anyone have any idea why PIL is loading my TIFF files
>> as signed integers?
>
> Could be that something goes wrong on the way to numpy.  What values
> do you get from PIL's own access methods (e.g. getpixel)?
>
> Also, what platform is this on?
>
> </F>
>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: PIL: TIFF images loaded as 16 bit signed integers

Chris Mitchell-2
You are right, when I look at the values obtained via getdata that are
passed to numpy there is no problem.  The issue is getting the pixel
values with getpixel, which for certain size data sets is faster than
using getdata.  Basically if the dataset is less than a certain size,
building my array via iterating with getpixel is faster than loading a
512x512 image into an array.  Because my readout was using a small
testarea, getpixel was being used and not getdata.

On Sun, Aug 1, 2010 at 6:20 PM, Sebastian Haase <[hidden email]> wrote:

> Chris,
>
> in you code:
> np.where(self.pixels<0,  ......
>
> how is this supposed to work, if self.pixels was defined as a
> *unsigned* unit16 ndarray ... ?
> (it would by definition not ever be pixels < 0 .... )
>
>
> - Sebastian Haase
>
> On Mon, Aug 2, 2010 at 12:11 AM, Chris Mitchell <[hidden email]> wrote:
>> My platform is windows 7 64bit, and when I do this:
>>
>> import Image
>> im = Image.open(file)
>> print im.getpixel((168,78)) #pixel intensity is 65535, gives -1 as value
>> print im.getpixel((169,78)) #pixel intensity is 64453, gives -1083 as value.
>>
>>
>> On Sun, Aug 1, 2010 at 7:14 AM, Fredrik Lundh <[hidden email]> wrote:
>>> 2010/7/6 Chris Mitchell <[hidden email]>:
>>>> I'm running into a problem where my image intensities are being loaded
>>>> as 16 bit signed integers.  The code I'm using to open the tiff file
>>>> is:
>>>>
>>>> im = Image.open(file)
>>>> self.pixels = np.array([im.getdata()], np.uint16)
>>>>
>>>> the filetype is a 16bit TIFF, whose intensities load fine into ImageJ.
>>>>  I load their intensities into a numpy 16bit array, and for the time
>>>> being I've fixed this problem with this code:
>>>>
>>>> np.where(self.pixels<0, -1*self.pixels+(32768+self.pixels),self.pixels)
>>>>
>>>> That basically takes any negative values and compensates for the
>>>> rollover.  Does anyone have any idea why PIL is loading my TIFF files
>>>> as signed integers?
>>>
>>> Could be that something goes wrong on the way to numpy.  What values
>>> do you get from PIL's own access methods (e.g. getpixel)?
>>>
>>> Also, what platform is this on?
>>>
>>> </F>
>>>
>> _______________________________________________
>> Image-SIG maillist  -  [hidden email]
>> http://mail.python.org/mailman/listinfo/image-sig
>>
>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig