{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport cv2\ntrain = pd.read_csv('../input/plant-pathology-2021-fgvc8/train.csv')\ntrain.head()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-07-15T01:37:28.108748Z","iopub.execute_input":"2021-07-15T01:37:28.109141Z","iopub.status.idle":"2021-07-15T01:37:28.295239Z","shell.execute_reply.started":"2021-07-15T01:37:28.109115Z","shell.execute_reply":"2021-07-15T01:37:28.294603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resize_img = '../input/resized-plant2021/img_sz_512'\ntest_img = '../input/plant-pathology-2021-fgvc8/test_images'\nsubmission = pd.read_csv('../input/plant-pathology-2021-fgvc8/sample_submission.csv')\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-15T01:37:32.064666Z","iopub.execute_input":"2021-07-15T01:37:32.065121Z","iopub.status.idle":"2021-07-15T01:37:32.078557Z","shell.execute_reply.started":"2021-07-15T01:37:32.065091Z","shell.execute_reply":"2021-07-15T01:37:32.077508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = './test_img_resize'\nif not os.path.isdir(path):\n    os.makedirs(path)","metadata":{"execution":{"iopub.status.busy":"2021-07-15T01:49:43.420238Z","iopub.execute_input":"2021-07-15T01:49:43.420805Z","iopub.status.idle":"2021-07-15T01:49:43.424610Z","shell.execute_reply.started":"2021-07-15T01:49:43.420747Z","shell.execute_reply":"2021-07-15T01:49:43.423853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_counts = submission.shape[0]\n\nfor i in range(img_counts):\n    img = cv2.imread('../input/plant-pathology-2021-fgvc8/test_images/' + submission.loc[i,'image'])\n    img = cv2.resize(img,(640,640))\n    #cv2.imshow('img'+str(i),img)\n    b,g,r = cv2.split(img)\n\n    kernel_size = 5\n    blur = cv2.GaussianBlur(g,(kernel_size, kernel_size), 0)\n    blur = cv2.GaussianBlur(blur,(kernel_size, kernel_size), 0)\n    \n    edges = cv2.Canny(blur, 30, 200)\n    #cv2.imshow('edges'+str(i),edges)\n    edge_box = []\n    for x in range(edges.shape[0]):\n        for y in range(edges.shape[1]):\n            if edges[x][y] != 0:\n                edge_box.append((x, y))\n                \n    row_min = edge_box[np.argsort([box[0] for box in edge_box])[0]][0]\n    row_max = edge_box[np.argsort([box[0] for box in edge_box])[-1]][0]\n    col_min = edge_box[np.argsort([box[1] for box in edge_box])[0]][1]\n    col_max = edge_box[np.argsort([box[1] for box in edge_box])[-1]][1]\n\n    test_img= img[row_min:row_max, col_min:col_max]\n    #cv2.imshow('cut'+str(i),new_img)\n    test_img_resize = cv2.resize(test_img,(512,512))\n    \n    path = './test_img_resize'\n    if not os.path.isdir(path):\n        os.makedirs(path)\n    \n    cv2.imwrite( './test_img_resize/' + submission.loc[i,'image'],test_img_resize)","metadata":{"execution":{"iopub.status.busy":"2021-07-15T01:58:49.807605Z","iopub.execute_input":"2021-07-15T01:58:49.808076Z","iopub.status.idle":"2021-07-15T01:58:54.634457Z","shell.execute_reply.started":"2021-07-15T01:58:49.808047Z","shell.execute_reply":"2021-07-15T01:58:54.633421Z"},"trusted":true},"execution_count":null,"outputs":[]}]}