Visual extraction in Refiner
This feature of Refiner will help you extract images from portions of similar documents and detect their contents, such as if a checkbox is checked or a signature line is signed, even if these regions aren’t always in the same locations across multiple documents.
By the end of this guide, you will be able to:
-
Create a Refiner workspace, and upload files for visual extraction.
-
Navigate the Refiner UI.
-
Define and create anchors based on consistent file structure.
-
Extract an image.
-
Use an extracted image to return a boolean for checkbox and signature completion.
1. Setting up your workspace
Refiner has a few built in project templates to help you get started quickly.
The Refiner project template
Activity:
-
Create a new workspace, and remove any starter folders.
-
Select New > New Project > Refiner Lesson 2 - Extracting Image Features, and name your project.
2. The Refiner UI
The .ibrefiner
file stores information about what you’ll be extracting from your uploaded files. This section breaks down how to navigate and edit the Refiner interface as a whole, beyond individual files.
Navigating the .ibrefiner
view
Activity:
-
From the
viewme.ibrecipebook
file, click on Edit in “Edit Refiner Program”. -
From the Document tab, click through each invoice file in turn. There might be a view delay after you select different files, but notice that each file has varying degrees of completion for their signature and checkbox fields.
-
Above each document, you can select the magnifying icons to change zoom levels, horizontal arrows for zoom to fit width, and vertical arrows for zoom to fit height.
-
The Fields column on the right of the page allows you to set extraction fields, which we’ll do in the activities below. Notice that the Output Table tab currently includes an example field, because we have not created any fields of our own.
-
In the Settings tab, ensure that “Enable Provenance Tracking” is on, as well as “Best Guess Provenance for UDFs”.
3. Defining anchors
Defining an anchor is the first step you need to take in any visual extraction workflow.
Anchors are simply Refiner functions that you believe will have a consistent location over all of your documents. Visual extraction uses them to figure out where in a record to locate the image, checkbox, or signature you want to extract. Anchor functions should not move page position in relation to the items that you’re extracting.
Discovering repeated text
In this task, we’ll try to decode the checkbox next to the phrase, “This is a domestic invoice”. Because this phrase should be a constant in our document templates, we can use it to discover the state of its nearby checkbox.
Activity:
-
From the Document tab in the
.ibrefiner
file, select thedocument-1.pdf.ibdoc
file. -
Hover over the existing
example_function
, and select the Red bin icon. -
In the “Fields” pane, select + New Field to add a new text anchor.
-
From the bottom pane, you can edit, rename, and test fields. Next to the “Text field” button, double click on
field_1
and replace the field name with__anchor_domestic
- The double underscore is a naming convention used to hide helper fields from being generated in your output and downstream applications like “Review OCR”.
-
In the text field below this title, where it reads “Enter Refiner Function..”, type
scan_line()
. Notice that the right side of the bottom pane now updates with relevant function documentation. -
Add two arguments to your function, so that it reads:
scan_line(INPUT_COL, 'This is a domestic invoice')
. -
Select Run, and see if your expected outcome is highlighted in red in the visual field, and follow it up with a Save to preserve your work. Note: You also could highlight the same field by using a combination of
match()
andlist_get()
! Try it out if you want a more advanced exercise.
4. Image extraction
After you’ve defined an anchor, you’ll want to use it to discover positionally relevant items.
Checkbox extraction
Because we’re working on visual extraction, we’ll create another function to extract an image of the nearby checkbox.
Activity:
-
From the Document tab in the
.ibrefiner
file, make sure you’re still located in thedocument-1.pdf.ibdoc
file. -
Create a new field using the same instructions as above, and rename it to
img_domestic_checkbox
.- Image extraction must begin with
img
. If you name it anything else, it will be encoded as a string, and you will not be able to preview your result effectively.
- Image extraction must begin with
-
To the left of the renamed field, click the Text Field button and change it to Visual Field.
-
Leave “Image Crop” as your default, but add
__anchor_domestic
as your “Anchor Field”. -
Return to your visual pane above. Use the Zoom in button to magnify your field, and scroll down until you find the checkbox located to the left of “This is a domestic invoice”.
-
Use your cursor to click and drag a square around the selected checkbox. If successful, you should have an orange-red box that surrounds the marked checkbox in your image.
-
Click Run, and then navigate to the Output Table tab. Select the first cell under
_img_domestic_checkbox
. -
If successful, you should be able to view the checkbox as an image from the Output tab in your bottom pane. Click Save to preserve your work.
5. Decoding an image
After you’ve extracted an image, you might want to create functionality to discover things like page completion, checkbox selection, or signatures.
Discovering a checkbox output via image functions
Because we’ve successfully extracted an image of a checkbox, we can use that knowledge to perform a similar step with built-in Instabase functionality. You’ll notice that the “Checkbox extraction” activity above is not required if you want to use this type of functionality in the future.
Activity:
-
Create a new field and name it
domestic_is_checked
. -
Convert this field to a Visual Field, and change the “Visual Function Type” to Checkbox. Again, use
__anchor_domestic
as the anchor. -
As before, return to your visual pane and zoom in to the same checkbox field. Use your cursor to box the selected checkbox field, then click Run.
-
Select the Output tab, where
True
should be the response. -
Navigate to Output Table, and notice the results. Which one is false? Click Save to preserve your work.
Discovering a checkbox output via text functions
This activity uses Instabase’s built-in functions on extracted images.
Activity:
-
Create a new text field and name it
domestic_is_checked_alternative
. -
In the text field below this title, where it reads “Enter Refiner Function..”, type
image_decode_checkbox()
-
Use
img_domestic_checkbox
as the function’s argument, then click Run. -
Select the Output Table tab, where
True
should be the response. -
Click Save to conclude the activity.
6. On your own—extracting a signature
Now that you’ve learned how to define anchors and extract images, use that knowledge to extract the signature field from each of the images. Feel free to use steps from the checkbox activity to help jog your memory if you get stuck.
Hints:
- Across each of the three invoice files, it looks like “Sincerely yours” is a common field.
- When you think you’ve completed the activity, click on the Output Table tab to view the fields you’ve returned across each image. Does each field return its expected result?
Conclusion
That’s it! You should now feel comfortable navigating and extracting visual fields in the Refiner app.
You should feel able to complete the following tasks:
-
Create a Refiner workspace, and upload files for visual extraction.
-
Navigate the Refiner UI.
-
Define and create anchors based on consistent file structure.
-
Extract an image.
-
Use an extracted image to return a boolean for checkbox and signature completion.
If not, reach out to us at training@instabase.com. We’d love to chat about any questions, comments, or concerns that you might’ve had in completing this guide.