comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: subset an image programatically
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: subset an image programatically [message #46831 is a reply to message #46826] Mon, 02 January 2006 02:44 Go to previous message
lbusett is currently offline  lbusett
Messages: 9
Registered: March 2004
Junior Member
Hi Javier,

the problem in your code seems to be that the ENVI_GET_ROI_DATA
command returns only the values of your image for the pixels that are
part of the ROI, but not their "position" in the image. If your ROI is
formed by 14000 pixels, the "roi_data" variable will be an array with
14000 elements, while the "output" that you want to write to disk is a
matrix with the same dimensions of the input image that contains data
only for the pixels that are contained in your ROI.
In order to perform your task, you have first of all to create a
"black" image with the same dimensions of the original image, then you
have to retrieve the position of each of the pixels of your ROI with
the "ENVI_GET_ROI" command, and finally you have to put the values that
you have retrieved with the ENVI_GET_ROI_DATA command in the correct
positions of the "black" image and write it to disk with the
ENVI_WRITE_ENVI_FILE command.
I think that something like this should work, at least if the images
that you want to subset are "1 band" images.

roi_data = ENVI_GET_ROI_DATA( roi_id, fid=fid, pos = [j])
ENVI_GET_ROI_INFORMATION, roi_id, ns=ns, nl=nl
roi_addresses = ENVI_GET_ROI(roi_id) ; Get the "position" of
the pixels in the ROI

out_data = intarr ( ns,nl,nb) ;
Create the "black" image"

out_data [*,*,*] = -9999 ; Assign a value to all the pixels of the
out image so that their values will not be "similar" to the values
that you extract from the ROI

out_data[roi_addresses] = roi_data ; Assign
values to the pixels of the output image that are in the ROI

ENVI_WRITE_ENVI_FILE, roi_data, ns=ns, nl=nl, $ ; Write the image
out_name='out_name', map_info=map_info

I didn't test it, so maybe it will not work properly.
If you have a single vector file that you are using to subset a series
of images with the same dimensions, i also think that you should take a
look at this thread:

http://groups.google.com/group/comp.lang.idl-pvwave/browse_t hread/thread/4b90c8f4a2c7b715/

Hope this helps,

Lorenzo

-----------------------------------------

Lorenzo Busetto
Environmental Dynamics Remote Sensing Lab.
University of Milano-Bicocca
email: lorenzo.busetto@unimib.it
tel: 00390264482848

Javier Martinez wrote:
> Hi everyone,
>
> this is my first post, I'm not a programmer and I'm trying to subset a
> series of images with vector files in evf format. Looking the envi and
> IDL help files and some code that I found in this group, I write the
> code below, and it works properly but not completely. In the final part
> where I write the envi file I obtain an image with all the roi data in
> a single line (more than 14000 samples) and I need the data in the
> original geographical shape (obviously).
>
> Thanks in advance for any help that you can give me
>
> happy new year for all you guys
>
> Javier Martinez Pincheira
> Instituto del Medio Ambiente
> Universidad de La Frontera
>
> pro batch_roi
> envi,/restore_base_save_files
> envi_batch_init, log_file='log.txt'
>
> envi_open_file, 'image', r_fid=fid
> envi_file_query, fid, ns=ns, nl=nl, nb=nb
>
> map_info = envi_get_map_info(fid=fid)
>
> evf_fname = 'vector.evf'
> evf_id = envi_evf_open(evf_fname)
>
> envi_evf_info, evf_id, num_recs=num_recs, $
> data_type=data_type, projection=projection, $
> layer_name=layer_name
>
>
>
> FOR i=0,num_recs-1 DO BEGIN
> ; read the record
> ;
> vec = ENVI_EVF_READ_RECORD(evf_id, i)
> xmap= vec(0,*)
> ymap= vec(1,*)
>
> ;just to verify
> print, 'Number of Records ' + ': ', num_recs
> print, 'Number of nodes in Record ' + $
> strtrim(i+1,2) + ': ', n_elements(vec[0,*])
>
> envi_convert_file_coordinates, fid1, xf, yf, xmap, ymap
>
>
> roi_id = ENVI_CREATE_ROI(ns=ns, nl=nl, color=4, name='shape')
>
>
> ENVI_DEFINE_ROI, roi_id, xpts=REFORM(xf, /over), $
> ypts=REFORM(yf, /over), /polygon
>
> FOR j=0,0 DO BEGIN
> ;print, roi_id
> roi_data = ENVI_GET_ROI_DATA( roi_id, fid=fid, pos = [j])
> ENVI_GET_ROI_INFORMATION, roi_id, ns=ns, nl=nl
>
> ENVI_WRITE_ENVI_FILE, roi_data, ns=ns, nl=nl,
> out_name='out_name', map_info=map_info
>
> ENDFOR
> ENDFOR
> print, roi_id
> ENVI_BATCH_EXIT
> end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Printing iTools window to PS file
Next Topic: Problem Compiling and Using Functions

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 03:17:05 PDT 2025

Total time taken to generate the page: 0.80161 seconds