Files
uiuc-ece391-mp3/helpers/uiuc.ipynb

91 lines
1.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from PIL import Image\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"img = Image.open('uiuc.png').convert('RGB')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(200, 720, 3)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.shape(img)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"f = open('uiuc_array.c', 'w')\n",
"for y in range(np.shape(img)[0]):\n",
" for x in range(np.shape(img)[1]):\n",
" r, g, b = np.array(img)[y, x, :]\n",
" data = ((r >> 3) << 11) + ((g >> 2) << 5) + (b >> 3)\n",
"# data = (r << 16) + (g << 8) + b\n",
" f.write('%s,' % hex(data))\n",
" if(24 == x % 30):\n",
" f.write('\\n')\n",
" f.write('\\n')\n",
"f.close()"
]
},
{
"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.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}