{"action":"opened","issue":{"url":"https://api.github.com/repos/python-pillow/Pillow/issues/3159","repository_url":"https://api.github.com/repos/python-pillow/Pillow","labels_url":"https://api.github.com/repos/python-pillow/Pillow/issues/3159/labels{/name}","comments_url":"https://api.github.com/repos/python-pillow/Pillow/issues/3159/comments","events_url":"https://api.github.com/repos/python-pillow/Pillow/issues/3159/events","html_url":"https://github.com/python-pillow/Pillow/issues/3159","id":330272169,"node_id":"MDU6SXNzdWUzMzAyNzIxNjk=","number":3159,"title":"Image conversion should scale pixel values accordingly","user":{"login":"SolarLiner","id":4302963,"node_id":"MDQ6VXNlcjQzMDI5NjM=","avatar_url":"https://avatars1.githubusercontent.com/u/4302963?v=4","gravatar_id":"","url":"https://api.github.com/users/SolarLiner","html_url":"https://github.com/SolarLiner","followers_url":"https://api.github.com/users/SolarLiner/followers","following_url":"https://api.github.com/users/SolarLiner/following{/other_user}","gists_url":"https://api.github.com/users/SolarLiner/gists{/gist_id}","starred_url":"https://api.github.com/users/SolarLiner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SolarLiner/subscriptions","organizations_url":"https://api.github.com/users/SolarLiner/orgs","repos_url":"https://api.github.com/users/SolarLiner/repos","events_url":"https://api.github.com/users/SolarLiner/events{/privacy}","received_events_url":"https://api.github.com/users/SolarLiner/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-07T13:28:04Z","updated_at":"2018-06-07T13:28:04Z","closed_at":null,"author_association":"NONE","body":"### What did you do?\r\nI tried to convert grayscale images of different modes together\r\n\r\n### What did you expect to happen?\r\nConversion should scale values; for example, converting from float to 8-bit should have the values scaled by 255, converting from 8-bit to 16-bit should have the values scaled by 65535/255, etc.\r\n\r\n### What actually happened?\r\nValues are being clamped\r\n```python\r\n>>> img = Image.open('16bit_image.png')\r\n>>> img.mode\r\n'I'\r\n>>> numpy.array(img)\r\narray([[51559, 52726, 50875, ..., 30493, 30991, 29907],\r\n       [51743, 52185, 51221, ..., 30841, 29920, 30793],\r\n       [51279, 50534, 51128, ..., 31532, 30852, 30651],\r\n       ...,\r\n       [28288, 27868, 28032, ..., 34367, 34235, 34312],\r\n       [26900, 27567, 28120, ..., 36229, 34607, 33399],\r\n       [27966, 28224, 27962, ..., 36223, 35851, 34477]], dtype=int32)\r\n>>> numpy.array(img.convert('L'))\r\narray([[255, 255, 255, ..., 255, 255, 255],\r\n       [255, 255, 255, ..., 255, 255, 255],\r\n       [255, 255, 255, ..., 255, 255, 255],\r\n       ...,\r\n       [255, 255, 255, ..., 255, 255, 255],\r\n       [255, 255, 255, ..., 255, 255, 255],\r\n       [255, 255, 255, ..., 255, 255, 255]], dtype=uint8)\r\n```\r\nFloating point data really doesn't go over well either\r\n```python\r\n>>> img_float = Image.fromarray(numpy.divide(numpy.array(img), 2**16-1))\r\n>>> numpy.array(img_float)\r\narray([[0.7867399 , 0.8045472 , 0.77630275, ..., 0.46529335, 0.47289234,\r\n        0.45635158],\r\n       [0.78954756, 0.79629207, 0.78158236, ..., 0.4706035 , 0.45654994,\r\n        0.46987107],\r\n       [0.78246737, 0.7710994 , 0.7801633 , ..., 0.48114747, 0.47077134,\r\n        0.46770427],\r\n       ...,\r\n       [0.4316472 , 0.42523843, 0.4277409 , ..., 0.5244068 , 0.52239263,\r\n        0.52356756],\r\n       [0.41046768, 0.42064545, 0.4290837 , ..., 0.55281913, 0.52806896,\r\n        0.50963604],\r\n       [0.4267338 , 0.43067065, 0.42667276, ..., 0.5527275 , 0.5470512 ,\r\n        0.5260853 ]], dtype=float32)\r\n>>> img_oct = img_float.convert('L')\r\n>>> numpy.array(img_oct)\r\narray([[0, 0, 0, ..., 0, 0, 0],\r\n       [0, 0, 0, ..., 0, 0, 0],\r\n       [0, 0, 0, ..., 0, 0, 0],\r\n       ...,\r\n       [0, 0, 0, ..., 0, 0, 0],\r\n       [0, 0, 0, ..., 0, 0, 0],\r\n       [0, 0, 0, ..., 0, 0, 0]], dtype=uint8)\r\n>>>\r\n```\r\n\r\nThe input image is a 16 bit PNG made with GIMP, as attached below.\r\n[terrain_input.png](https://user-images.githubusercontent.com/4302963/41102485-4aa81866-6a67-11e8-8766-deacf0874e88.png)\r\n\r\n\r\n### What versions of Pillow and Python are you using?\r\nUsing Python 3.6.5 and Pillow 5.1.0"}}
{"actor":{"display_login":"SolarLiner"}}