{"cells":[{"metadata":{},"cell_type":"markdown","source":"This initial step aims to acces zip data of plankton images. The code can list all files in the input folder. The code can also select and display a single or several plankton images"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\n\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Zip file of train dataset is held by a variable namely *files_in_zip*."},{"metadata":{"trusted":true},"cell_type":"code","source":"from zipfile import ZipFile\nfrom  matplotlib import pyplot as plt\n\ndatasetPath = '/kaggle/input/datasciencebowl'\n\nzip_path = '/kaggle/input/datasciencebowl/train.zip'\nwith ZipFile(zip_path) as myzip:\n    files_in_zip = myzip.namelist()\n    \nfiles_in_zip[:5]\n\nNMax = len(files_in_zip)\n\nprint(\"Total number of the train images is %d\"%(NMax))\n\n#files_in_zip[:5]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Display a single image of plankton\n\nimport random\n\nfileIdx = random.randint(0, NMax)\nif (fileIdx<3):\n    fileIdx = fileIdx + 5\n\nfrom PIL import Image\nwith ZipFile(zip_path) as myzip:\n    with myzip.open(files_in_zip[fileIdx]) as myfile:\n        img = Image.open(myfile)\n\n#print(img.size)\nM = img.size[0]\nN = img.size[1]\n\nMf = int((M/M)*5)\nNf = int((N/M)*5)\n\nimg.show()\nplt.rcParams[\"figure.figsize\"] = (Mf,Nf)\n\nplt.imshow(img, cmap=\"gray\")\nplt.title(\"File idx: \"+str(fileIdx) +\"  \"+myfile.name)\nplt.show()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\nidxF1 = 5000\nidxF2 = idxF1 + 10\n\nplt.rcParams[\"figure.figsize\"] = (20,10)\nidx = 0\n\nwith ZipFile(zip_path) as myzip:\n    for i in range(idxF1,idxF2,1):\n    \n        myfile = myzip.open(files_in_zip[i])\n        #print(str(idx)+\" \"+myfile.name)\n        idx = idx + 1\n        img = Image.open(myfile)       \n        \n        plt.subplot(2,5,idx)\n        plt.imshow(img, cmap=\"gray\")\n        plt.title(myfile.name)","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}