Tutorial: Image Extraction
Use Aryn DocParse to extract an image from a battery manual
Introduction
In this example, we’ll use DocParse to extract an image from a battery manual. We’ll go through the important code snippets below to see what’s going on.
Let’s focus on the following code that makes a call to Aryn DocParse API to extract the image from the PDF:
If you inspect the partitioned_file variable, you’ll notice that it’s a large JSON object with details about all the components in the PDF (checkout this page to understand the schema of the returned JSON object in detail). Below, we highlight the Image
element that contains the information about some of the images in the page:
In particular let’s look at the element which highlights the Image that has been detected.
Extracting the Image
This JSON object represents one of the images in the PDF. You’ll notice that the image’s binary representation, its bounding box (which indicates the coordinates of the image in the PDF), and certain other properties (image_mode, image_size etc.) are returned back. You can then process this JSON however you’d like for further analysis. In the notebook, we use the Pillow Image module from python to display the extracted image on its own.
Output Image
Here’s the output image after extraction. As you can see, the image has been successfully extracted from the PDF with clarity.
Was this page helpful?