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.
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)
.
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.
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. 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.
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. 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.
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.
Find all the indices corresponding to an object in an image:
img = FLTARR(512, 512) ; Create an image with different valued regions.
TVSCL, img ; Display the image.
region = SEARCH2D(img, 175, 300, 0.6, 0.8, /DIAGONAL)
;
Search for an object starting at (175, 300) whose data values are between (0.6) and (0.8).
img = BYTSCL(img, TOP=127B) ; Scale the background cells into the range 0 to 127.
img[region] = 255B ; Highlight the object region by setting it to 255.
TVSCL, img ; Display the array with the highlighted object in it.