{"cells":[{"cell_type":"markdown","metadata":{"_cell_guid":"fa3c424d-5952-e059-7fa1-066d16b81f21"},"source":"I hadn't noticed (https://www.kaggle.com/vfdev5/noaa-fisheries-steller-sea-lion-population-count/traindotted-train-for-3-7-9-jpg) which also shows thes differences\n\n## This kernel compares the images in train and train dotted\nApart from the blacked out areas\nI noticed differences in train_id: 3, 7 and 9.\n7 seems to be mirrored . For these images dot extraction based on difference wont work."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"8b230928-2c7b-05ae-e0bb-f822a39c8e4a"},"outputs":[],"source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport cv2\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output.\n\n%matplotlib inline "},{"cell_type":"markdown","metadata":{"_cell_guid":"d341b036-b436-f135-17ab-e4dad886ab2e"},"source":"#### Load the train data"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"2c751f39-2177-b852-2c5b-7f921f6aa4d8"},"outputs":[],"source":"train = pd.read_csv('../input/Train/train.csv')"},{"cell_type":"markdown","metadata":{"_cell_guid":"18bff545-6c87-6d10-da20-a83be0eef620"},"source":"#### Define a helper function for loading images"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"5a9f2d0c-fbb9-ddf3-15d5-8fde9f70372d"},"outputs":[],"source":"def image_from_id(id,data='Train',dotted=False,inputdir=r'../input/'):\n    if dotted:\n        dr=inputdir + data + r'Dotted/'\n    else:\n        dr=inputdir + data + r'/'\n    fname = dr + str(id) + '.jpg'\n    return cv2.cvtColor(cv2.imread(fname), cv2.COLOR_BGR2RGB), fname"},{"cell_type":"markdown","metadata":{"_cell_guid":"e0e4ff52-9aee-a269-12af-38d5cfd69b93"},"source":"#### Now plot the images and see the differences"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"c454cf9e-fb95-29a8-f2b1-c5c224d166b9"},"outputs":[],"source":"ntrain=11\nf, ax = plt.subplots(11,3,figsize=(15,6*ntrain))\nfor i in range(ntrain):\n    img, fname = image_from_id(i)\n    img_dot, fname = image_from_id(i,dotted=True)\n    \n    diff = cv2.absdiff(img_dot, img)\n    gray = cv2.cvtColor(diff, cv2.COLOR_RGB2GRAY)\n    ret,diff_mask = cv2.threshold(gray,0,255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)\n    \n    ax[i][0].imshow(img_dot)\n    ax[i][1].imshow(img)\n    ax[i][2].imshow(diff_mask,'gray')\n    ax[i][0].set_title('train_id: ' + str(i))\n    ax[i][1].set_title('train_id: ' + str(i) + ' (dotted)')\n    ax[i][2].set_title('train_id: ' + str(i) + ' (diff_mask)')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"fca2369b-0ea7-e98f-2f28-9bc9141e4588"},"outputs":[],"source":""}],"metadata":{"_change_revision":0,"_is_fork":false,"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.6.0"}},"nbformat":4,"nbformat_minor":0}