Skip to content

Instantly share code, notes, and snippets.

@furas
Last active August 5, 2020 11:54
Show Gist options
  • Save furas/0210ce506e182dfd23c580290dbd382d to your computer and use it in GitHub Desktop.
Save furas/0210ce506e182dfd23c580290dbd382d to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"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 0x7F5574744490>"
]
},
"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": 3,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQAAAABYmaj5AAAAJUlEQVR4nGNgQAH1////////AITDhCI1yhvljfJGeaM88nioAAC2Vgb9hDlwcAAAAABJRU5ErkJggg==\n",
"text/plain": [
"<PIL.Image.Image image mode=1 size=100x100 at 0x7F55746C2D30>"
]
},
"execution_count": 3,
"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": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQAAAABYmaj5AAAAH0lEQVR4nGNgQAH1/xHgAROK1ChvlDe4eKNgFAxVAAD2uwy11U7oWwAAAABJRU5ErkJggg==\n",
"text/plain": [
"<PIL.Image.Image image mode=1 size=100x100 at 0x7F557464D070>"
]
},
"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[y,x] = True # note that rows and columns are reversed\n",
" \n",
"Image.fromarray(ary)"
]
},
{
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
import sys
import PIL
import numpy
import notebook
print('Platform:', sys.platform) # linux
print('Python :', sys.version.replace('\n', '')) # 3.7.8 (default, Jun 29 2020, 05:44:46) [GCC 7.5.0]
print('PIL :', PIL.__version__) # 7.0.0
print('numpy :', numpy.__version__) # 1.18.4
print('notebook:', notebook.__version__) # 6.0.3
import platform
print('System :', platform.system(), platform.version()) # Linux #46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment