You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
11 KiB
Plaintext
174 lines
11 KiB
Plaintext
4 years ago
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Image Processing "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"from PIL import Image\n",
|
||
|
"import aalib"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 25,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"im1 = Image.open(\"Imageresearch/A3.2.png\")\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 26,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"(3508, 4961)"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 26,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"im1.size"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 27,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"im4 = im1\n",
|
||
|
"im5 = im4.convert(\"L\")\n",
|
||
|
"im6 = im5.convert(\"1\")\n",
|
||
|
"im6.save ('A3.2C.png')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 42,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|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HrJTLgD+aVddExlMUKJkDhNsi3xQSLIGd2bar+THA06UwLusdhC1GhIerN8Taj1oKiQy3ouCresu4umXS3gNihDoS51WuxpIB8NtucfQZi3dncd23ZvaLhfwObIYm/SSkFqy7jAsqvF1dyIBhb9bgNVKT5oqnjXCLM0lYVcDRlTk0qrOfph6M7CG9AhfaK6GuniTmTDLYBfTv5byPMotiPg4nhHbi0I86Fx/cDCHhrGYPY2ksjIVUy8c8wN6Q6Et9G8LGzZWNW4zVnVcT8pvgB4DEpGZQuQvngO5EfgJ8wM7zZ++9cfbuC2chJOHVBF8Pdhi5kEvYi2bq3d59t2ecFf1r4tG9iwwbQEjG46QVzl9cvUUBpEKVm+JUfUU8/dut+yu/enOr/+ZY/EwIIcTX303F52K31v6ff/9XQUcUru/CEocp3fa5Jg+vkPYTIO3cAJ4kbnwb7v4ekAykBl0xHytaUHuXzii/24PHCQTuNUKbPBm3BDYfUOSlsS9ReYTGpP3xxpXhWSbj9QSg04DwINl8uHZivqYs3j0WHg/XV38JeiwSB2HzRgp5MharEph6gCmVG0SnhKiLVSG+/Q/x7ftCbLrO1//17Ue1Fz9aFx99Lr7unxZCiN/VBR3xO3EkhOD+MrnlL8XrE+BRpwE827xBRn7pIL+ELBqTDl/OwvU6Qojxf34rHp8W34ppvyOE+PuPBXf5vI749lp/sy/Ed6vi70RdiE3xuNooIIDnk81aj6DMfqcBBKFSzEP1Tr4GhJmnmC6h/cFnKojOhlIpbIjrqTbu7gug+slBrbN4EktauX4BIFwTj/DAk2vPgxpvaaB/+2C9GbCmPJaat9MB1xGvWPD+jFDAo04C9FXn8nYBS5sxXcr
|
||
|
"text/plain": [
|
||
|
"<PIL.Image.Image image mode=1 size=400x328 at 0xAFE8DCF0>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 42,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"im1.convert(\"L\")\n",
|
||
|
"im3 = im1.resize((new_width, new_height), Image.ANTIALIAS)\n",
|
||
|
"im3.save('resized.png')\n",
|
||
|
"im3"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 17,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"im3.convert(\"1\")\n",
|
||
|
"im4 = im3.convert(\"1\")\n",
|
||
|
"im4.save('def1.png')\n",
|
||
|
"\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 73,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"ename": "FileNotFoundError",
|
||
|
"evalue": "[Errno 2] No such file or directory: 'Imageresearch/Everett.cat.png'",
|
||
|
"output_type": "error",
|
||
|
"traceback": [
|
||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
|
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
|
||
|
"\u001b[0;32m<ipython-input-73-66253b0a1980>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mtest\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mImage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Imageresearch/Everett.cat.png\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mtest1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mImage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Imageresearch/def1.png\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/PIL/Image.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(fp, mode, formats)\u001b[0m\n\u001b[1;32m 2889\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2890\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mfilename\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2891\u001b[0;31m \u001b[0mfp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbuiltins\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"rb\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2892\u001b[0m \u001b[0mexclusive_fp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2893\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'Imageresearch/Everett.cat.png'"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"test = Image.open(\"Imageresearch/Everett.cat.png\")\n",
|
||
|
"test1 = Image.open(\"Imageresearch/def1.png\")"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 62,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"(588, 400) (400, 500)\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"print (test.size, test1.size)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"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.3"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|