{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","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\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Agenda, load the segmentation model, get the mask, binarize it\n\nimport torch\nimport torchvision\nimport torch.nn as nn\nimport torch.optim as optim\nimport torchvision.transforms as transforms\nfrom torch.utils.data import DataLoader\nfrom torch.utils.data import Dataset\nfrom torch.utils.tensorboard import SummaryWriter\nfrom torchvision import models\n\nfrom skimage import io\nfrom skimage.transform import resize\nfrom skimage.color import rgb2gray,gray2rgb\nfrom matplotlib import pyplot as plt\n\nimport csv\nimport numpy as np\nimport cv2","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"## Testing simple Image read / EDA\nimport csv\nimport numpy as np\n\nfilename = \"../input/hpa-single-cell-image-classification/train.csv\"\nfields = [] \nrows = [] \ncodes = [\n'Nucleoplasm',\n'Nuclear membrane',\n'Nucleoli',\n'Nucleoli fibrillar center',\n'Nuclear speckles',\n'Nuclear bodies',\n'Endoplasmic reticulum',\n'Golgi apparatus',\n'Intermediate filaments',\n'Actin filaments',\n'Microtubules',\n'Mitotic spindle',\n'Centrosome',\n'Plasma membrane',\n'Mitochondria',\n'Aggresome',\n'Cytosol',\n'Vesicles and punctate cytosolic patterns',\n'Negative'\n]\n\nl = [0] * 19\n\n# reading csv file \nwith open(filename, 'r') as csvfile: \n    # creating a csv reader object \n    csvreader = csv.reader(csvfile) \n    \n    fields = next(csvreader)\n    # extracting each data row one by one \n    for row in csvreader: \n        rows.append(row) \n    \n    for row in rows[:50]: # Reading the First image and label\n        image_id = row[0]\n        labels = row[1]\n        labels = labels.replace(\"|\",\",\")\n        list_labels = list(labels.split(\",\")) \n        \n        if(len(list_labels) == 1):\n            for i in list_labels:\n                l[int(i)] +=1 \n                \n        \n\n        img_blue = io.imread(\"../input/hpa-single-cell-image-classification/train/\"+ image_id+\"_blue.png\")\n        img_green = io.imread(\"../input/hpa-single-cell-image-classification/train/\"+ image_id+\"_green.png\")\n        img_red = io.imread(\"../input/hpa-single-cell-image-classification/train/\"+ image_id+\"_red.png\")\n        img_yellow = io.imread(\"../input/hpa-single-cell-image-classification/train/\"+ image_id+\"_yellow.png\")\n        \n        #https://www.kaggle.com/thedrcat/hpa-single-cell-classification-eda/comments#Contents\n        rgb = np.dstack((img_red,img_yellow,img_blue))\n        gray =  cv2.cvtColor(rgb, cv2.COLOR_BGR2GRAY)\n        ret,thresh1 = cv2.threshold(gray,10,255,cv2.THRESH_BINARY)\n        ret,thresh2 = cv2.threshold(img_blue,10,255,cv2.THRESH_BINARY)\n        ret,thresh3 = cv2.threshold(img_green,10,255,cv2.THRESH_BINARY)\n        fig, ax = plt.subplots(1,4, figsize=(20,50))\n        \n\n        sub = thresh1 - thresh2\n        \n       \n        \n        ax[0].imshow(rgb)\n        ax[0].axis('off')\n        \n        ax[1].imshow(thresh2,cmap=\"gray\")\n        ax[1].axis('off')\n        \n        ax[2].imshow(thresh3,cmap=\"gray\")\n        ax[2].axis('off')\n        \n        ax[3].imshow(sub,cmap=\"gray\")\n        ax[3].axis('off')\n        \n#         ax[3].imshow(img_blue)\n#         ax[3].axis('off')\n        plt.show()\n        \n\n\n\nprint(l)\nprint(codes)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\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}