X
5210

The IDL "LABEL_REGION" function considers edge pixel data to be zero

DISCUSSION:

The IDL Help reference page for the LABEL_REGION function mentions:

    "Pixels at the edges of Data are considered to be zero."

Consequently, if non-zero edge pixel data must be considered in the results from LABEL_REGION, then you'll need to pad the original data edges with a column and row of zeroes, so that LABEL_REGION will be able to "see" the original edge pixels when calculationg the results.

This Help Article provides an example IDL program that illustrates how to get LABEL_REGION to consider edge pixel data.

EXAMPLE:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;+
; :Description:
;   Exelis Visual Information Solutions Technical Support example
;   illustrating a method for including edge pixel data in
;   the results when using the LABEL_REGION() function -- by
;   expanding/padding the borders of the original data with zeros.
;   (By default, the algorithm used by LABEL_REGION() considers
;   all edge pixel data to be zero, even when it is non-zero.)
;-
PRO ex_label_region_edge

  ; Input data
  data = [ [1, 1, 1, 0, 0],  $
    [1, 1, 0, 0, 1], $
    [1, 1, 0, 0, 0], $
    [0, 0, 0, 1, 1], $
    [0, 1, 1, 1, 1], $
    [0, 1, 1, 1, 1] ]
    
  ; Get array size/type information
  struct = SIZE(data, /STRUCTURE)
 
  ; Create temp array with original array dimensions + 2
  tmpdims = struct.dimensions[0:1]+2
  tmp = MAKE_ARRAY(tmpdims, TYPE=struct.TYPE)
 
  ; Assign original data to center of new array
  tmp[1:-2,1:-2] = data
 
  tmp = LABEL_REGION(tmp)
 
  ; Extract the labeled regions to an array of the original size
  labels = tmp[1:-2,1:-2]
 
  PRINT, 'Input data:'
  PRINT, data
  PRINT
  PRINT, 'LABEL_REGION() output without edge pixel data (default):'
  PRINT, LABEL_REGION(data)
  PRINT
  PRINT, 'LABEL_REGION() output including edge pixels:'
  PRINT, labels
  PRINT
END
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

The output from the example program,should look like this:

IDL> ex_label_region_edge
% Compiled module: EX_LABEL_REGION_EDGE.
Input data:
       1       1       1       0       0
       1       1       0       0       1
       1       1       0       0       0
       0       0       0       1       1
       0       1       1       1       1
       0       1       1       1       1

LABEL_REGION() output without edge pixel data (default):
       0       0       0       0       0
       0       1       0       0       0
       0       1       0       0       0
       0       0       0       2       0
       0       2       2       2       0
       0       0       0       0       0

LABEL_REGION() output including edge pixels:
       1       1       1       0       0
       1       1       0       0       2
       1       1       0       0       0
       0       0       0       3       3
       0       3       3       3       3
       0       3       3       3       3