EXTRACTOBJECTS Procedure
Getting Started: EXTRACTOBJECTS Procedure
(View the complete code for this example.)
The example in this section shows how to use the EXTRACTOBJECTS procedure in conjunction with PROC LOADIMAGES and PROC FEDSQL to highlight detected objects in an image.
The following PROC LOADIMAGES statement loads an image into the mylib.images table. You can use the PRINT procedure to display the contents of this table. Also, you can use the DISPLAYIMAGES procedure to display the original input image.
proc loadimages libref=mylib path='path/to/birds.png';
output out=mylib.images addvars=(width height);
run;
proc print data=mylib.images;
run;
proc displayimages data=mylib.images;
run;
Figure 1 shows that the mylib.images table contains an image with a height of 448 pixels and a width of 448 pixels.
Figure 1: The mylib.images Table
| Obs | _width_ | _height_ | _image_ | _size_ | _path_ | _type_ | _id_ |
|---|---|---|---|---|---|---|---|
| 1 | 448 | 448 | ... | 457024 | /path/to/birds.png | png | 1 |
Figure 2 shows the ODS output of PROC DISPLAYIMAGES.
Figure 2: Original Input Image

You can use PROC FEDSQL as follows to add the object annotations in RECT format (see the section Supported Image Annotation Formats) to the mylib.images table. Because there are two birds in the input image, you can add annotations for two objects.
proc fedsql sessref=mysess;
create table images_annotations as
select
*,
2 as "_nObjects_",
'bird0' as "_Object0_",
4 as "_Object0_x", 23 as "_Object0_y",
201 as "_Object0_width", 144 as "_Object0_height",
'bird1' as "_Object1_",
191 as "_Object1_x", 116 as "_Object1_y",
197 as "_Object1_width", 147 as "_Object1_height"
from
images;
quit;
Note: These statements create the mylib.images_annotations table by using the image binaries and metadata from the mylib.images table and adding annotation variables in RECT format. By default, PROC EXTRACTOBJECTS assumes that coordinates are in RECT format. Therefore, you must specify the following variables for each detected object in the mylib.images_annotations table, where N denotes the Nth detected object:
_ObjectN__ObjectN_x_ObjectN_y_ObjectN_width_ObjectN_height
The following PROC PRINT statement displays the mylib.images_annotations table, which is generated by the previous statements:
proc print data=mylib.images_annotations;
run;
Figure 3 shows the mylib.images_annotations table.
Figure 3: The mylib.images_annotations Table
| Obs | _width_ | _height_ | _image_ | _size_ | _path_ | _type_ | _id_ | _nObjects_ | _Object0_ | _Object0_x | _Object0_y | _Object0_width | _Object0_height | _Object1_ | _Object1_x | _Object1_y | _Object1_width | _Object1_height |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 448 | 448 | ... | 457024 | /path/to/birds.png | png | 1 | 2 | bird0 | 4 | 23 | 201 | 144 | bird1 | 191 | 116 | 197 | 147 |
Finally, you use PROC EXTRACTOBJECTS as follows to highlight the two birds in the original image and save the output in the mylib.objects table:
proc extractobjects data=mylib.images_annotations
coordinateformat=rect maxobjects=2;
output out=mylib.objects;
run;
You can use PROC PRINT as follows to display the mylib.objects table. Again, you can use PROC DISPLAYIMAGES to display the highlighted image.
proc print data=mylib.objects;
run;
proc displayimages data=mylib.objects;
run;
Figure 4 shows that the mylib.objects table resembles a typical image table.
Figure 4: The mylib.objects Table
| Obs | _image_ | _size_ | _path_ | _type_ |
|---|---|---|---|---|
| 1 | ... | 479240 | /path/to/birds.png | png |
Figure 5 shows the ODS output of PROC DISPLAYIMAGES.
Figure 5: Visualization of Object Detections
