{"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":"markdown","source":"# Whale Tail Manual Background Removal","metadata":{}},{"cell_type":"code","source":"import cv2\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2023-05-12T06:16:17.990121Z","iopub.execute_input":"2023-05-12T06:16:17.990583Z","iopub.status.idle":"2023-05-12T06:16:17.996893Z","shell.execute_reply.started":"2023-05-12T06:16:17.990546Z","shell.execute_reply":"2023-05-12T06:16:17.995157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path='/kaggle/input/happy-whale-and-dolphin/train_images/00144776eb476d.jpg'\nimg=cv2.imread(path)\nimg=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)\nimg=cv2.resize(img, dsize=None, fx=0.1, fy=0.1)\nplt.imshow(img)\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-12T06:23:52.509642Z","iopub.execute_input":"2023-05-12T06:23:52.510099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"H=img.shape[0]\nW=img.shape[1]\nprint(H,W)","metadata":{"execution":{"iopub.status.busy":"2023-05-12T06:23:54.755301Z","iopub.execute_input":"2023-05-12T06:23:54.756644Z","iopub.status.idle":"2023-05-12T06:23:54.762880Z","shell.execute_reply.started":"2023-05-12T06:23:54.756590Z","shell.execute_reply":"2023-05-12T06:23:54.761371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Ps=[[0,0],[10,0],[0,10], \n    [H-1,0],[H-11,0],[H-1,10], \n    [0,W-1],[10,W-1],[0,W-11], \n    [H-1,W-1],[H-11,W-1],[H-1,W-11]]\n\nfor P in Ps:\n    p0=P[0]\n    p1=P[1]\n    a0=img[p0,p1,0]*0.7\n    a1=img[p0,p1,0]*1.3\n    b0=img[p0,p1,1]*0.7\n    b1=img[p0,p1,1]*1.3\n    c0=img[p0,p1,2]*0.7\n    c1=img[p0,p1,2]*1.3\n\n    for h in range(H):\n        for w in range(W):\n            if a0<img[h,w,0]<a1 and b0<img[h,w,1]<b1 and c0<img[h,w,2]<c1:\n                img[h,w,:]=np.array([255,255,255])\n                \nplt.imshow(img)\nfor yx in Ps:\n    y=yx[0]\n    x=yx[1]\n    plt.plot(x,y,'ro',markersize=1)\nplt.axis('off')\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}