Re: Apply a shapefile to raster images in IDL [message #41337 is a reply to message #41289] |
Thu, 07 October 2004 05:08   |
lbusett
Messages: 9 Registered: March 2004
|
Junior Member |
|
|
Hi Jenny,
If your images are all of the same size I think that you can solve
your problem simply by using ENVI.
1: Open one of your images and load it in a display
2: Convert your shapefile to an ENVI vector file (EVF) by clicking
> Vector > Open Vector File > Shapefile
3: Load your vector on the display where you have loaded your
image (In the "available vectors list" select the vector, then click
on "load" and then on "Diplay# (your_display)"
4:In the "Vector Parameters" window that appears, select "File >
Export active layer to ROI"
5: Select "basic tools > masking > build mask" and select your
display
6: Select "Options > Import ROIS", then select the ROI you created
from your vector and click on "OK". Next, choose a name for the mask
file that you want to create and click on "Apply". Now, in the
"available bands list you should see a new image, which has value 0
outside the vector and 1 inside it.
7: Now, you can use this "0-1" image as a mask for your image. Go
to Basic tools > apply mask. Select one of the images that you want to
mask, then click on "Select mask band" and select the mask image.
Click on "OK".
If you have many images and you don't want to repeat n-times the
last step you can use an IDL procedure that automatically opens the
images and apply the mask on each one.
I think that something like this should work: it's a simple
modification of the example program that you can find on the ENVI
User's guide.
pro multiple_mask
; Select input files (Select all your images)
files_list = dialog_pickfile(/READ,title ='Select input$
files',/multiple_files)
; Select the mask File
mask_file = dialog_pickfile(/read, title = 'Select Mask File')
envi_open_file, mask_file, r_fid=m_fid
; Count the number of files
num_files = N_elements (files_list)
for count = 0, num_files-1 do begin
; Selects the n- file. Output file name is
"input_file_name"+"-masked"
in_file = files_list [count]
out_file =files_list [count]+'-masked'
envi_open_file, in_file, r_fid=fid
if (fid eq -1 or m_fid eq -1) then return
; get some useful information and set the output filename.
envi_file_query, fid, ns=ns, nl=nl, nb=nb, bname=bname
; Set the keyword parameters
dims = [-1l, 0, ns-1, 0, nl-1]
pos = lindgen(nb)
m_pos = [0]
; Call the 'doit' to apply the mask
envi_mask_apply_doit, fid=fid, pos=pos, dims=dims,m_fid=m_fid,$
m_pos=m_pos, value=0, out_name=out_file, in_memory=0, $
r_fid=r_fid
endfor
end
I hadn't fully tested it, but it should work.
Hope this helps,
Lorenzo
|
|
|