{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom pathlib import Path \nimport cv2\nimport time ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"new_dir_name = \"norm_minmax01_images_try2\"","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"BASE_DIR = Path('/kaggle/input/cassava-leaf-disease-classification')\n\ntrain = pd.read_csv(BASE_DIR/'train.csv')\n\ntrain = train.loc[0:10, :]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def load_image(path , image_id):\n    image = cv2.imread(path + image_id)\n    return cv2.cvtColor(image, cv2.COLOR_BGR2RGB).astype(np.uint8)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def norm_img(general_path , img_path, new_general_path):\n    \"\"\"\n    norm img nim , max 0,1 for RGB images \\\n    \n    \n    \n    \"\"\"\n    img = load_image(general_path , img_path)\n    norm_image = cv2.normalize(img , None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX,\n                               dtype=cv2.CV_32F)\n    \n    print(norm_image)\n    cv2.imwrite(new_general_path +  img_path  , cv2.cvtColor(norm_image , cv2.COLOR_RGB2BGR))\n    print(1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"general_path = r\"/kaggle/input/cassava-leaf-disease-classification/train_images/\"\n\nos.makedirs ('/kaggle/working/' + new_dir_name )\nnew_general_path = r'/kaggle/working/'+ new_dir_name + '/'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# # for i in [0]:\n# img_path = train.loc[0, \"image_id\"]\n# img = load_image(general_path , img_path)\n# norm_image = cv2.normalize(img , None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX,\n#            dtype=cv2.CV_32F)\n# #     im.save(save_path)\n# cv2.imwrite(new_general_path +  img_path  , cv2.cvtColor(norm_image , cv2.COLOR_RGB2BGR))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"a = time.time()\ntrain[\"image_id\"].apply(lambda x: norm_img(general_path , x, new_general_path))\nb = time.time()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for root, dirs, files in os.walk(new_dir_name):\n    print(root)\n    print( dirs)\n    print(files)\n    print()\n    print()\n    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.imread('/kaggle/working/norm_minmax01_images_try2/1000910826.jpg')\n\nplt.imshow()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import zipfile\nfrom tqdm import tqdm\n\n\ndef zip_and_remove(path):\n    ziph = zipfile.ZipFile(f'{path}.zip', 'w', zipfile.ZIP_STORED)\n    \n    for root, dirs, files in os.walk(path):\n        for file in files:\n            file_path = os.path.join(root, file)\n            ziph.write(file_path)\n            os.remove(file_path)\n    \n    ziph.close()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"zip_and_remove(new_dir_name)\n","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}