{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# 🎨 Justin Faler \n# 📆 8/30/2019\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 seaborn as sns\n%matplotlib inline\nfrom skimage.io import imread, imshow, imsave\nfrom skimage.filters import prewitt_h,prewitt_v\nfrom skimage.color import rgb2hsv\nimport scipy.misc\nimport scipy.ndimage\nimport sklearn.metrics\nfrom sklearn.cluster import KMeans\nfrom skimage import measure\nimport imageio\nimport cv2\nimport skimage.io\nimport os","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df = pd.read_csv('../input/recursion-cellular-image-classification/pixel_stats.csv')\ndf2 = pd.read_csv(\"../input/recursion-cellular-image-classification/test_controls.csv\")\ndf3 = pd.read_csv('../input/recursion-cellular-image-classification/train_controls.csv')\ntrain = pd.read_csv('../input/recursion-cellular-image-classification/train.csv')\ntest = pd.read_csv('../input/recursion-cellular-image-classification/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(train.head())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(df.head())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(df2.head())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(df3.head())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(test.head())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_img_f = '../input/recursion-cellular-image-classification/test/HUVEC-21/Plate3/H05_s2_w3.png'\nim = skimage.io.imread(test_img_f)\nim_g = skimage.io.imread(test_img_f, as_gray=True)\n\n#skimage.io.imshow(im)\nim.dtype","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nimage = imread('../input/recursion-cellular-image-classification/test/HUVEC-21/Plate3/H05_s2_w3.png', as_gray=True)\nimshow(image)\nplt.ylabel('Height {}'.format(image.shape[0]))\nplt.xlabel('Width {}'.format(image.shape[1]))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Photo negative\nplt.figure(figsize=(20, 15))\nnegative = 255 - image # neg = (L-1) - img\nplt.ylabel('Height {}'.format(image.shape[0]))\nplt.xlabel('Width {}'.format(image.shape[1]))\nplt.imshow(negative);","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Contouring"},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(15, 15))\npic = imageio.imread('../input/recursion-cellular-image-classification/test/HUVEC-21/Plate3/H05_s2_w3.png')\n\nh,w = pic.shape[:2]\n\nim_small_long = pic.reshape((h * w, 1))\nim_small_wide = im_small_long.reshape((h,w,1))\n\nkm = KMeans(n_clusters=2)\nkm.fit(im_small_long)\n\nseg = np.asarray([(1 if i == 1 else 0)\n                  for i in km.labels_]).reshape((h,w))\n\ncontours = measure.find_contours(seg, 0.5, fully_connected=\"high\")\nsimplified_contours = [measure.approximate_polygon(c, tolerance=5) \n                       for c in contours]\n\nplt.figure(figsize=(20,15))\nfor n, contour in enumerate(simplified_contours):\n    plt.plot(contour[:, 1], contour[:, 0], linewidth=2)\n    \n    \nplt.ylim(h,0)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Matrix 🔴🆚🔵💊\nimage = imread('../input/recursion-cellular-image-classification/test/HUVEC-21/Plate3/H05_s2_w3.png')\nimage.shape, image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df2 = pd.DataFrame(np.random.rand(10, 11), columns=['id_code', 'experiment', 'mean', 'std', 'plate','well', 'site', 'channel', 'median', 'min', 'max'])\ndf2.plot.bar(figsize=(20,15));","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Correlation Matrix of Global Variables"},{"metadata":{"trusted":true},"cell_type":"code","source":"corr = df2.corr()\nfig = plt.figure(1, figsize=(20,15))\nplt.imshow(corr,cmap='winter')\nlabels = np.arange(len(df2.columns))\nplt.xticks(labels,df2.columns,rotation=90)\nplt.yticks(labels,df2.columns)\nplt.title('Correlation Matrix of Global Variables')\ncbar = plt.colorbar(shrink=0.85,pad=0.02)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### A histogram for each numerical attribute"},{"metadata":{"trusted":true},"cell_type":"code","source":"df.hist(bins=50, figsize=(20,15))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Plot Pixel Stats"},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(); df.plot(figsize=(15,10))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Plot Test Dataframe"},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(); df2.plot(figsize=(15,10))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.pairplot(df2,hue='channel',height=2.6)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.loc[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = imread('../input/recursion-cellular-image-classification/test/HUVEC-21/Plate3/H05_s2_w3.png')\nprint('Type of the image : ' , type(image))\n\nprint('Shape of the image : {}'.format(image.shape))\n\nprint('Image Hight {}'.format(image.shape[0]))\n\nprint('Image Width {}'.format(image.shape[1]))\n\nprint('Dimension of Image {}'.format(image.ndim))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = imread('../input/recursion-cellular-image-classification/test/HUVEC-21/Plate3/H05_s2_w3.png')\nprint('Image size {}'.format(image.size))\n\nprint('Maximum RGB value in this image {}'.format(image.max()))\n\nprint('Minimum RGB value in this image {}'.format(image.min()))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(15, 15))\ngrayscale = imread('../input/recursion-cellular-image-classification/test/HUVEC-21/Plate3/H05_s2_w3.png')\ncounts, vals = np.histogram(grayscale, bins=range(2 ** 8))\nplt.plot(range(0, (2 ** 8) - 1), counts)\nplt.title('Grayscale image histogram')\nplt.xlabel('Pixel intensity')\nplt.ylabel('Count')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.size","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.isnull().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# look at the last 5 rows\ndf.tail()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.describe()\nprint(\"*\"*50)\ndf.info()\nprint(\"*\"*50)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df2","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":1}