Hi all,
I've written the code below to create a routine to shrink an ENVI ROI
by 1 pixel on each side. The way it does this (probably not the most
efficient way) is to get the points for the ROI, set all those points
to 1 in a 2D array the size of the image, and then use the CONVOL
function to find all points that are not surrounded by ones.
I've got that bit of the code worked out fine, but when I tell ENVI to
create a ROI with the points that I've decided should be in the new,
shrunk ROI, it seems to go strange. It doesn't give any error
messages, but when I then ask for all the points in that new ROI back
it gives me a crazy list with all the X values as zero, and the Y
values correct.
Does anyone have any idea what's going on with this? I've been
struggling with it for a few days now, and suspect it's going to be
something silly - I just can't see what it is.
Code below:
PRO SHRINK_ROI, fid, roi_id
; Get the number of samples
ENVI_FILE_QUERY, fid, ns=ns, nl=nl
; Get the array of 1D points then convert them to actual x and y co-
ords
points = ENVI_GET_ROI(roi_id)
if points[0] EQ -1 THEN RETURN
image_array = intarr(ns, nl)
;x_points = intarr(N_ELEMENTS(points))
;y_points = intarr(N_ELEMENTS(points))
;FOR i = 0, N_ELEMENTS(points) - 1 DO BEGIN
;x_points[i] = points[i] MOD ns
;y_points[i] = points[i] / ns
;ENDFOR
point_indices = ARRAY_INDICES(image_array, points)
print, "POINT INDICES"
print, point_indices
image_array[point_indices[0, *], point_indices[1, *]] = 1
help, image_array
; Create the kernel for the summing CONVOL operation
Kernel = FLTARR(3, 3)
Kernel[0, *] = [0, 1, 0]
Kernel[1, *] = [1, 1, 1]
Kernel[2, *] = [0, 1, 0]
; Create an image where each element is the sum of the elements
within
; 3 pixels
summed_image = CONVOL(image_array, Kernel, /CENTER, /EDGE_TRUNCATE)
help, summed_image
where_answer = WHERE(summed_image EQ 5, count)
IF count EQ 0 THEN RETURN
new_indices = ARRAY_INDICES(summed_image, where_answer)
print, "NEW INDICES ARE:"
print, new_indices
new_x_indices = new_indices[0, *]
new_y_indices = new_indices[1, *]
new_roi_id = ENVI_CREATE_ROI(nl=nl, ns=ns, name="Shrunk ROI")
ENVI_DEFINE_ROI, new_roi_id, /point, xpts=new_x_indices,
ypts=new_y_indices
; Extra testing bit of code. Here is where I find that the ROI
points come back differently.
resulting_points = ENVI_GET_ROI(new_roi_id)
resulting_point_indices = ARRAY_INDICES(image_array,
resulting_points)
print, "Resulting POINT INDICES"
print, resulting_point_indices
print, "All done"
END
PRO SHRINK_ALL_ROIS
ENVI_SELECT, fid=fid
print, fid
roi_ids = ENVI_GET_ROI_IDS(fid=fid)
FOR i = 0, N_ELEMENTS(roi_ids) - 1 DO BEGIN
print, "DOING ROI ID ", roi_ids[i]
SHRINK_ROI, fid, roi_ids[i]
ENDFOR
END
Cheers,
Robin
|