Skip to content

Instantly share code, notes, and snippets.

@1f0
Created August 25, 2021 05:05
Show Gist options
  • Save 1f0/c38880b3af026a8634ce0980aa0876b5 to your computer and use it in GitHub Desktop.
Save 1f0/c38880b3af026a8634ce0980aa0876b5 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import cv2\n",
"c=cv2.imread('test.png')\n",
"cv2.imwrite('q0.png', c, [cv2.IMWRITE_PNG_COMPRESSION, 0])\n",
"cv2.imwrite('q9.png', c, [cv2.IMWRITE_PNG_COMPRESSION, 9])"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"q9.png 825350 bytes\n",
"q0.png 6231996 bytes\n"
]
}
],
"source": [
"import os\n",
"import glob\n",
"for i in glob.glob('q*.png'):\n",
" print(i, os.path.getsize(i), 'bytes')"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.0 0.0\n"
]
}
],
"source": [
"import numpy as np\n",
"q0 = cv2.imread('q0.png')\n",
"q9 = cv2.imread('q9.png')\n",
"print(np.linalg.norm(q0-c), np.linalg.norm(q9-c))"
]
},
{
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment