{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import tensorflow as tf\nimport cv2\nimport sys\nfrom matplotlib import pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"a = cv2.imread('../input/siim-isic-melanoma-classification/jpeg/train/ISIC_0075663.jpg')\na = cv2.resize(a , (224,224), interpolation=cv2.INTER_AREA)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"quals = [100, 98, 95, 90, 80, 70, 60, 50, 40, 30, 20, 10]\nencodes = [cv2.imencode('.jpg', a, (cv2.IMWRITE_JPEG_QUALITY, i))[1].tostring() for i in quals]\ndecodes = [tf.io.decode_jpeg(i) for i in encodes]\nsize_of_origin = sys.getsizeof(encodes[0])\ncompress_rate = [sys.getsizeof(i)/size_of_origin for i in encodes]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### compare details in 5x5","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"k_low =110\nk_size=5\nplt.figure(figsize=(16, 6))\nfor i in range(12):\n    plt.subplot(2, 6, i+1)\n    plt.imshow(decodes[i][k_low:k_low+k_size, k_low:k_low+k_size, :])\n    plt.title(f'q:{quals[i]} r:{compress_rate[i]: .3f}')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### compare details in 10x10","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"k_low =110\nk_size=10\nplt.figure(figsize=(16, 6))\nfor i in range(12):\n    plt.subplot(2, 6, i+1)\n    plt.imshow(decodes[i][k_low:k_low+k_size, k_low:k_low+k_size, :])\n    plt.title(f'q:{quals[i]} r:{compress_rate[i]: .3f}')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### compare details in 20x20","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"k_low =110\nk_size=20\nplt.figure(figsize=(16, 6))\nfor i in range(12):\n    plt.subplot(2, 6, i+1)\n    plt.imshow(decodes[i][k_low:k_low+k_size, k_low:k_low+k_size, :])\n    plt.title(f'q:{quals[i]} r:{compress_rate[i]: .3f}')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### compare details in 50x50","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"k_low =110\nk_size=50\nplt.figure(figsize=(16, 6))\nfor i in range(12):\n    plt.subplot(2, 6, i+1)\n    plt.imshow(decodes[i][k_low:k_low+k_size, k_low:k_low+k_size, :])\n    plt.title(f'q:{quals[i]} r:{compress_rate[i]: .3f}')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## summary\n1. the details lost obviously when the quality less than 90.\n2. the increase of compressing rate reduced by the decay of quality.\n3. 95 maybe a better choise.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}