EXTRACTOBJECTS Procedure

Example 7.2 Visualize Detections in COCO Format

(View the complete code for this example.)

This example shows how to use the EXTRACTOBJECTS procedure to visualize object detections that are provided in COCO format. For more information about annotation formats, see the section Supported Image Annotation Formats.

The following PROC FEDSQL statement adds the object detections in COCO format to the image table. It is assumed that the input image is loaded in the mylib.images table.

proc fedsql sessref=mysess;
   create table coco_annotations as
   select
      *,
      2 as "_nObjects_",

      'bird0' as "_Object0_", 0.92 as "_P_Object0_",
      4 as "_Object0_xmin", 23 as "_Object0_ymin",
      205 as "_Object0_xmax", 177 as "_Object0_ymax",

      'bird1' as "_Object1_", 0.84 as "_P_Object1_",
      191 as "_Object1_xmin", 116 as "_Object1_ymin",
      388 as "_Object1_xmax", 263 as "_Object1_ymax"
   from
      images;
quit;

Note: These statements create the mylib.coco_annotations table by using the image binaries and metadata from the mylib.images table and adding annotation variables in COCO format. Ensure that the following variables are specified for each detected object in the mylib.coco_annotations table, where N denotes the Nth detected object:

  • _ObjectN_

  • _ObjectN_xmin

  • _ObjectN_ymin

  • _ObjectN_xmax

  • _ObjectN_ymax

You can also provide the probability values for each object detection as follows: _P_ObjectN_, where N denotes the Nth detected object.

The following PROC PRINT statement displays the contents of the mylib.coco_annotations table, which is generated by the previous statements:

proc print data=mylib.coco_annotations;
run;

Output 7.2.1 shows the mylib.coco_annotations table.

Output 7.2.1: The mylib.coco_annotations Table

Obs_width__height__image__size__path__type__id__nObjects__Object0__P_Object0__Object0_xmin_Object0_ymin_Object0_xmax_Object0_ymax_Object1__P_Object1__Object1_xmin_Object1_ymin_Object1_xmax_Object1_ymax
1448448...457024/path/to/birds.pngpng12bird00.92423205177bird10.84191116388263


The following statements highlight the two detected objects in the input image by using the annotations that are provided in COCO format. The resulting table, mylib.objects, contains images that have visualizations.

proc extractobjects data=mylib.coco_annotations
   coordinateformat=coco maxobjects=2 method=highlight;
   output out=mylib.objects;
run;

Output 7.2.2 shows the output image with two objects highlighted, along with their probabilities.

Output 7.2.2: Visualization of Object Detections and Probabilities

Visualization of Object Detections and Probabilities


Last updated: March 26, 2026