{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# 🎨 Justin Faler \n# 📆 8/30/2019\n# 🦅 Mt. San Jacinto College\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\nimport cv2 # opencv version 3.4.2\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\nimport matplotlib as mpl\nfrom skimage import measure\nimport imageio\nimport os","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"df = pd.read_csv('../input/open-images-2019-object-detection/sample_submission.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('# File sizes')\nfor f in os.listdir('../input'):\n    if not os.path.isdir('../input/' + f):\n        print(f.ljust(30) + str(round(os.path.getsize('../input/' + f) / 1000000, 2)) + 'MB')\n    else:\n        sizes = [os.path.getsize('../input/'+f+'/'+x)/1000000 for x in os.listdir('../input/' + f)]\n        print(f.ljust(30) + str(round(sum(sizes), 2)) + 'MB' + ' ({} files)'.format(len(sizes)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import skimage\nimport skimage.io\n\ntest_img_f = '../input/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg'\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":"image = imread('../input/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg', 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":"image = imread('../input/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg')\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/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg')\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":"# RGB to HSV(Hue, Saturation, Value)\ninp_image = imread(\"../input/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg\")\nhsv_img = rgb2hsv(inp_image)\nplt.ylabel('Height {}'.format(image.shape[0]))\nplt.xlabel('Width {}'.format(image.shape[1]))\nimshow(hsv_img)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"grayscale = imread('../input/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg')\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":"pic = imageio.imread('../input/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg')\n\nh,w = pic.shape[:2]\n\nim_small_long = pic.reshape((h * w, 3))\nim_small_wide = im_small_long.reshape((h,w,3))\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=(5,10))\nfor n, contour in enumerate(simplified_contours):\n    plt.plot(contour[:, 1], contour[:, 0], linewidth=2)\n    \n    \nplt.ylim(h,0)\nplt.axes().set_aspect('equal')\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = imread('../input/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg')\n\n'''\nLet's pick a specific pixel located at 100 th Rows and 50 th Column. \nAnd view the RGB value gradually. \n'''\n\nimage[ 100, 50 ]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = imread('../input/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg')\n# A specific pixel located at Row : 100 ; Column : 50 \n# Each channel's value of it, gradually R , G , B\n\nprint('Value of only R channel {}'.format(image[ 100, 50, 0]))\n\nprint('Value of only G channel {}'.format(image[ 100, 50, 1]))\n\nprint('Value of only B channel {}'.format(image[ 100, 50, 2]))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.title('R channel')\n\nplt.ylabel('Height {}'.format(image.shape[0]))\n\nplt.xlabel('Width {}'.format(image.shape[1]))\n\nplt.imshow(image[ : , : , 0])\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.title('G channel')\n\nplt.ylabel('Height {}'.format(image.shape[0]))\n\nplt.xlabel('Width {}'.format(image.shape[1]))\n\nplt.imshow(image[ : , : , 1])\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.title('B channel')\n\nplt.ylabel('Height {}'.format(image.shape[0]))\n\nplt.xlabel('Width {}'.format(image.shape[1]))\n\nplt.imshow(image[ : , : , 2])\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Photo negative\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":{"trusted":true},"cell_type":"code","source":"# Here is that cup in a matrix 🔴🆚🔵💊\nimage = imread('../input/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg')\nimage.shape, image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = imread('../input/open-images-2019-object-detection/test/1ae704327598297d.jpg') \nimage.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Lets generate some edge detection\nimage = imread('../input/open-images-2019-object-detection/test/d0d394a4b854c49d.jpg',as_gray=True)\n\n#calculating horizontal edges using prewitt kernel\nedges_prewitt_horizontal = prewitt_h(image)\n#calculating vertical edges using prewitt kernel\nedges_prewitt_vertical = prewitt_v(image)\n\nimshow(edges_prewitt_vertical, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Print the size of the sample submission\ndf.size","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Print the shape \ndf.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df","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":"df.isnull().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.head","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":"df.dtypes","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}