{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Cropped image dataset","metadata":{}},{"cell_type":"markdown","source":"This dataset is generated on the top of the original image dataset.\n\n## **It may be useful for us to do plot type classification**","metadata":{}},{"cell_type":"markdown","source":"## This notebook provides a new dataset that contains all images that have been cropped. ","metadata":{}},{"cell_type":"markdown","source":"`Benetech - Making Graphs Accessible-Cropped Images` includes all images, and it is **public. Please feel free to use it if it is helpful!**\n\n\n\nThe cropped images only include the main body (dot, bar, line, scatter) of the original image. Drop all text or numerical content in the original graph. ","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport os\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as patches\nfrom PIL import Image\nfrom itertools import cycle\nfrom pathlib import Path\n\nimport json","metadata":{"execution":{"iopub.status.busy":"2023-04-26T13:01:03.094687Z","iopub.execute_input":"2023-04-26T13:01:03.095127Z","iopub.status.idle":"2023-04-26T13:01:03.127670Z","shell.execute_reply.started":"2023-04-26T13:01:03.095088Z","shell.execute_reply":"2023-04-26T13:01:03.126618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Here I just select one pair of images to describe the cropped graph","metadata":{}},{"cell_type":"code","source":"with open('/kaggle/input/benetech-making-graphs-accessible/train/annotations/0000ae6cbdb1.json', 'r') as f:\n    data = json.load(f)\n\nnormalized_data = pd.json_normalize(data)","metadata":{"execution":{"iopub.status.busy":"2023-04-26T13:15:01.517543Z","iopub.execute_input":"2023-04-26T13:15:01.517960Z","iopub.status.idle":"2023-04-26T13:15:01.526388Z","shell.execute_reply.started":"2023-04-26T13:15:01.517925Z","shell.execute_reply":"2023-04-26T13:15:01.524908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Flatten the json data\nprint(normalized_data)","metadata":{"execution":{"iopub.status.busy":"2023-04-26T13:16:32.570804Z","iopub.execute_input":"2023-04-26T13:16:32.571222Z","iopub.status.idle":"2023-04-26T13:16:32.603763Z","shell.execute_reply.started":"2023-04-26T13:16:32.571185Z","shell.execute_reply":"2023-04-26T13:16:32.602441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(1, 2, figsize=(15, 10))\n\nfig.tight_layout()\nax = ax.flatten()\n\nwith Image.open('/kaggle/input/benetech-making-graphs-accessible/train/images/0000ae6cbdb1.jpg') as img:\n    ax[0].imshow(img)\n    # remove the axis labels and ticks from the show\n    ax[0].axis('off')\n\nwith Image.open('/kaggle/input/benetech-making-graphs-accessible-cropped-images/0000ae6cbdb1_vertical_bar.jpg') as img:\n    ax[1].imshow(img)\n    # remove the axis labels and ticks from the show\n    ax[1].axis('off')\n","metadata":{"execution":{"iopub.status.busy":"2023-04-26T13:25:39.416685Z","iopub.execute_input":"2023-04-26T13:25:39.417102Z","iopub.status.idle":"2023-04-26T13:25:39.898400Z","shell.execute_reply.started":"2023-04-26T13:25:39.417065Z","shell.execute_reply":"2023-04-26T13:25:39.897214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The _**left**_ graph is the original one.\n\nThe _**right**_ graph is the cropped one.\n\nThe cropped version drops all the text and numerical content from the original graph.\n\nIt is easy for us to do classification when using models.","metadata":{}},{"cell_type":"markdown","source":"# Naming Conventions for New Images","metadata":{}},{"cell_type":"markdown","source":"## **The name of the cropped graph file follows: `unique values as prefix` + '_'+ `plot type as suffix`**","metadata":{}},{"cell_type":"markdown","source":"e.g.\n\nFor json and image pair which with unique value: `0000ae6cbdb1`.\n\nIn annotation: the json file naming as:`0000ae6cbdb1.json`,\n\nIn images: the jpg file naming as: `0000ae6cbdb1.jpg`,\n\nIn cropped-images: the new jpg file naming as: `0000ae6cbdb1_vertical_bar.jpg`, because the plot type is `vertical_bar`.\n\nThe naming rule is easy for us to grab the image and corresponding plot type. ","metadata":{}}]}