jimgardener wrote: > hi > i am getting value of a pixel of a greyscale image using PIL's > image.getdata and need to pack it as an int as below > > ie greyvalues > 127 , 56 , 135 , 99 , 102 , 101 , 146 , 112 , 155 , 154 , 112 , 169 > > should become > -4473925, -8289919, -4144960, -5789785, -5592406, -5658199 ,-3684409, > -5131855, -3289651,-3355444, -5131855, -2763307 > > (i got these values using java's BufferedImage class..)I would like to > know if there is a way to do the conversion in python.(.i need 'these > 'for some calculations)
I have no idea how the bytes from PIL are possibly mapped to the wicked numbers Java seems to generate (although there might be some systematics to it). But judging from the fact that 112->-5131855 appears twice, I presume as last resort you could create an explicit mapping of 0..255 to the values Java generates. To get these, create an image, 256 pixels wide, one high, with grey-values from #000000 to #ffffff. Then build up the mapping. Not elegant, but works. Diez -- http://mail.python.org/mailman/listinfo/python-list