Created
August 5, 2020 11:13
-
-
Save nlothian/0c985ff4beaf0a3fbb0507a24805eb83 to your computer and use it in GitHub Desktop.
Weird PIL behaviour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numpy==1.19.1 | |
opencv-python==4.3.0.36 | |
Pillow==6.1.0 | |
rope==0.17.0 | |
scipy==1.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"from PIL import Image\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQAAAABYmaj5AAAAH0lEQVR4nGNgQAH1/xHgAROK1ChvlDe4eKNgFAxVAAD2uwy11U7oWwAAAABJRU5ErkJggg==\n", | |
"text/plain": [ | |
"<PIL.Image.Image image mode=1 size=100x100 at 0x10A099310>" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"img = Image.new('1', (100, 100))\n", | |
"img_pixels = img.load()\n", | |
"\n", | |
"for x in range(1, 99):\n", | |
" for y in range(1, 50):\n", | |
" img_pixels[x,y] = True\n", | |
" \n", | |
"img" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQAAAABYmaj5AAABRElEQVR4nJ3TwU0DMRCF4d+Tlcgt6SAt0EFaooNQAiVRAiWEDiY3kEIeB89u3goWrfDJyurZ840n4KvZXpeY9gfBUPvNFaC+na4AbwDsJEkf0KDdpvOC4w3gvQE0AXz1w56QpOdK5wCXPVQ61PZApft6kCRdq0Dd0wdJUvYCJUljSpL02tNJL7D/ngFtO/LgbOksnqUnHs15hPP6fVXgKTGecnAe4bxcz+sdVH+AR4ynHOBz29NAzHj8bM7vPJrzCONtEuMpMZ5ycF6toyTpvJ7Xv9QRx8R4ysF5xP941cHi7bkXuFFiPCXGU/bA2JwAZqO9yMNfLwOw0TaecnBercXRXuLVfZVOjKfEeEqMV77p7WM1Dx/OjBkP4ymHZryX9TyclwH+zzWeEuONEzU2pzmP+IOH8XaJ8ZQx42G88b6l0XbeNxjR0nx4GObZAAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<PIL.Image.Image image mode=1 size=100x100 at 0x10A12AD90>" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ary = np.zeros((100,100), dtype=np.bool)\n", | |
"\n", | |
"for x in range(1, 99):\n", | |
" for y in range(1, 50):\n", | |
" ary[x,y] = True\n", | |
" \n", | |
"Image.fromarray(ary)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQAAAABYmaj5AAABfElEQVR4nF2UsW3DMBREj5RBIICBtOkyQyawZsoC9gqZIF4lEyhbKOUn5CaC5UtBiv8YVfwg7x/fkSKgX5Axc2zjVwKHOh7uAFDnzncAde7Z6ooDEB5NG3HyAoHi8A62b6K1uTUBzX1MZTFJzmWtBQLbUBfkCFwHb7t4U+kJ4OfJq21wh6ouiqK2CAC8HPetkpP0XFNrmuPoRetCko+zeTXJXtYE59vVgkcLdDzk2OEpEd7EbxbabZAEq1rwCp/jQfBo4VeIsvrdNr8TvByddpKsSzjVvYUjeLRAx0OOiqcJ8iQJzpLgNkiCu1rwaLHDg+D1dwIf4rfUc294+9wkunr2xd3PXvBo4S5EOUqxwhPEmJx2lp2VcCpfC0fwaLHDg+DRNMFPqRY6X1ULXnXfr3aOHR4E71+CX1KtSV6NMXmCs+jq2ZeVfvaCR4sdnvptN0nwOniCC51vVwtecW9/bo4dHgSPFl984lvc1ySvRlELXuXbr3aOHR4Ej/YHVaYa99Zkzj8AAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<PIL.Image.Image image mode=1 size=100x100 at 0x10A138150>" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ary = np.zeros((100,100), dtype=np.bool)\n", | |
"\n", | |
"for x in range(1, 99):\n", | |
" for y in range(1, 50):\n", | |
" ary[y,x] = True # note that rows and columns are reversed\n", | |
" \n", | |
"Image.fromarray(ary)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your code works for me without problems.
https://gist.github.com/furas/0210ce506e182dfd23c580290dbd382d