{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np \nimport pandas as pd\nimport os\nprint(os.listdir(\"../input\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd\ndf = pd.read_csv(\"../input/train.csv\")\ndf.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%matplotlib inline\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport numpy as np\nfrom PIL import Image\nimport matplotlib.patches as patches\nimport cv2\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Visualizing random characters from the Kuzushiji dataset."},{"metadata":{"trusted":true},"cell_type":"code","source":"kal = np.random.randint(1337)\nsal = str(df.loc[kal][1]).split()\nprint(df.loc[kal][0])\nimg = np.array(Image.open('../input/train_images/'+str(df.loc[kal][0])+'.jpg'), dtype=np.uint8)\nfig,ax = plt.subplots(1)\n#fig = plt.figure()\nX = []\nfor i in range(0,len(sal),5):\n    rect = patches.Rectangle((int(sal[i+1]),int(sal[i+2])),int(sal[i+3]),int(sal[i+4]),linewidth=1,edgecolor='r',facecolor='none')\n    ax.add_patch(rect)\n    X.append(img[int(sal[i+2]):int(sal[i+2])+int(sal[i+4]),int(sal[i+1]):int(sal[i+1])+int(sal[i+3]),:])\n'''for i in range(0,len(X)):\n    imgnew = Image.fromarray(X[0])\n    fig.add_subplot(i,2,1)\n    imgplot = plt.imshow(imgnew)\nplt.show()\n#imgi = plt.imshow(img)'''\n#show_images(X)\nxa = Image.fromarray(X[0])\nedges = cv2.Canny(X[0],100,200)\nplt.imshow(edges,cmap='gray')\n#plt.imshow(img)\nplt.show()\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"A function to visualize a list of images."},{"metadata":{"trusted":true},"cell_type":"code","source":"def show_images(images, cols = 1, titles = None):\n    \"\"\"Display a list of images in a single figure with matplotlib.\n    \n    Parameters\n    ---------\n    images: List of np.arrays compatible with plt.imshow.\n    \n    cols (Default = 1): Number of columns in figure (number of rows is \n                        set to np.ceil(n_images/float(cols))).\n    \n    titles: List of titles corresponding to each image. Must have\n            the same length as titles.\n    \"\"\"\n    assert((titles is None)or (len(images) == len(titles)))\n    n_images = len(images)\n    if titles is None: titles = ['Image (%d)' % i for i in range(1,n_images + 1)]\n    fig = plt.figure()\n    for n, (image, title) in enumerate(zip(images, titles)):\n        a = fig.add_subplot(cols, np.ceil(n_images/float(cols)), n + 1)\n        if image.ndim == 2:\n            plt.gray()\n        plt.imshow(image)\n        a.set_title(title)\n    fig.set_size_inches(np.array(fig.get_size_inches()) * n_images)\n","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}