The SEARCH2D function finds “objects” or regions of similar data values within a two-dimensional array. Given a starting location and a range of values to search for, SEARCH2D finds all the cells within the array that are within the specified range and have some path of connectivity through these cells to the starting location. In addition to searching for cells within a global range of data values, SEARCH2D can also search for adjacent cells whose values deviate from their neighbors within specified tolerances.

This routine is written in the IDL language. Its source code can be found in the file search2d.pro in the lib subdirectory of the IDL distribution.

Examples


Find all the indices corresponding to an object in an image:

; Create an image with different valued regions:
img = FLTARR(512, 512)
img[3:503, 9:488] = 0.7
img[37:455, 18:438] = 0.5
img[144:388, 90:400] = 0.7
img[200:301, 1:255] = 1.0
img[155:193, 333:387] = 0.3
TVSCL, img   ;Display the image.
; Search for an object starting at (175, 300) whose data values are
; between (0.6) and (0.8):
region = SEARCH2D(img, 175, 300, 0.6, 0.8, /DIAGONAL)
; Scale the background cells into the range 0 to 127:
img = BYTSCL(img, TOP=127B)
; Highlight the object region by setting it to 255:
img[region] = 255B
; Display the array with the highlighted object in it:
TVSCL, img

Syntax


Result = SEARCH2D( Array, Xpos, Ypos, Min_Val, Max_Val [, DECREASE=value, INCREASE=value[, LPF_BAND=integer{3}]] [, /DIAGONAL] )

Return Value


SEARCH2D returns a longword array that contains a list of the array subscripts that define the located object or region. The original X and Y indices of the array subscripts returned by SEARCH2D can be found with the following IDL code:

index_y = Result / (SIZE(Array))[1]
index_x = Result - (index_y * (SIZE(Array))[1])

where Result is the array returned by SEARCH2D and Array is the original input array. The object within Array can be subscripted as Array(Region) or Array(index_x, index_y).

Arguments


Array

A two-dimensional array, of any data type, to be searched.

Xpos

The X coordinate (dimension 0 of Array) of the starting location.

Ypos

The Y coordinate (dimension 1 of Array) of the starting location.

Min_Val

The minimum data value for which to search. All array subscripts of all cells that are connected to the starting cell, and have a value between Min_Val and Max_Val (inclusive) are returned.

Max_Val

The maximum data value for which to search.

Keywords


DECREASE

This keyword and the INCREASE keyword allow you to compensate for changing intensities of data values within an object. An edge-enhanced copy of Array is made and compared to the orginal array if this keyword is set. The search is limited to pixels for which the edge-enhanced gradient value lies between the DECREASE and INCREASE values. When DECREASE or INCREASE is set, any adjacent cells are found if their corresponding data values in the edge enhanced array are greater than DECREASE and less than INCREASE. In any case, the adjacent cells will never be selected if their data values are not between Min_Val and Max_Val. The default for this keyword is 0.0 if INCREASE is specified.

INCREASE

This keyword and the DECREASE keyword allow you to compensate for changing intensities of data values within an object. An edge-enhanced copy of Array is made and compared to the orginal array if this keyword is set. The search is limited to pixels for which the edge-enhanced gradient value lies between the DECREASE and INCREASE values. When DECREASE or INCREASE is set, any adjacent cells are found if their corresponding data values in the edge enhanced array are greater than DECREASE and less than INCREASE. In any case, the adjacent cells will never be selected if their data values are not between Min_Val and Max_Val. The default for this keyword is 0.0 if DECREASE is specified.

LPF_BAND

Set this keyword to an integer value of 3 or greater to perform low-pass filtering on the edge-enhanced array. The value of LPF_BAND is used as the width of the smoothing window. This keyword is only effective when the DECREASE or INCREASE keywords are also specified. The default is no smoothing.

DIAGONAL

Set this keyword to cause SEARCH2D to find cells meeting the search criteria whose surrounding squares share a common corner. Normally, cells are considered adjacent only when squares surrounding the cells share a common edge. Setting this option requires more memory and execution time.

Version History


Pre-4.0

Introduced

See Also


SEARCH3D