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_
1448448...457024/path/to/birds.pngpng1


Figure 2 shows the ODS output of PROC DISPLAYIMAGES.

Figure 2: Original Input Image

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
1448448...457024/path/to/birds.pngpng12bird0423201144bird1191116197147


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.pngpng


Figure 5 shows the ODS output of PROC DISPLAYIMAGES.

Figure 5: Visualization of Object Detections

Visualization of Object Detections


Last updated: March 26, 2026