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 by roi in idl
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: subset an image by roi in idl [message #50307] Tue, 26 September 2006 09:48 Go to next message
peter.eddy@shaw.ca is currently offline  peter.eddy@shaw.ca
Messages: 19
Registered: March 2005
Junior Member
Jeff N.
If I understand correctly from your comment..

gis_learner wrote:
> 3) as you said the roi's are as big as the original image. I tried to
> define ROI from the subsetted images so that I can use in the original
> ones.. But the result is terrible.....

ROI's in ENVI are referenced by pixel coordinates (not geo-coordinates)
so if you try to use roi boundarys (dims= ) on two images with
different x y extents (nl= | ns= ) it will not work.

If you like you can email me directly, and I'll give you a hand. We
dont want to turn this group into >> idl-pvwave-ENVI-techsupport. ;)

Pete
Re: subset an image by roi in idl [message #50315 is a reply to message #50307] Tue, 26 September 2006 04:45 Go to previous messageGo to next message
gis_learner is currently offline  gis_learner
Messages: 7
Registered: September 2006
Junior Member
Dear Jeff,

Thank you very much for the quick answer.
I saw that there are three main issues in your mail
1) the file name issue.... it is corrected
2) the r_fid issue.. I hope you can verify that it is correct at below

name='C:\RSI\IDL61\subset_via_roi\bhtmref_roi1.roi'
envi_restore_rois,name
roi_ids = envi_get_roi_ids(fid=fid)
roi_addr=envi_get_roi(roi_ids)

print, 'ROI: ', name, n_elements(roi_addr)
print,'name=',name, ' roi_ids=',roi_ids

roi_data=envi_get_roi_data(roi_ids,fid=fid,pos=[0])
envi_get_roi_information,roi_ids,ns=ns,nl=nl
print, 'ns= ',ns, '**nl=',nl
roi_adresses=envi_get_roi(roi_ids)

out_data = intarr(ns,nl)
out_data [roi_adresses]=roi_data
envi_write_envi_file,
out_data,ns=ns,nl=nl,out_name='out_name',map_info=map_info

3) as you said the roi's are as big as the original image. I tried to
define ROI from the subsetted images so that I can use in the original
ones.. But the result is terrible. I may appreciate any help

Best Regards


Jeff N. yazdi:
> The first thing I'd suggest doing would be to clean up your code.
> That's the easiest way to spot mistakes, and there are a few here you
> should fix. First, you assign the filename for can_tmr.img to the
> variable 'img_file', but then in the next line you try to open
> 'image_file' - see the difference? Also, i'm surprised this code is
> even running b/c of this line:
>
> roi_ids = envi_get_roi_ids(fid=r_fid)
>
> The variable r_fid is undefined, as I see it. Once you get past these
> things I think you'll be in a much better position to figure out for
> yourself why your code isn't doing what you think it should. You
> might, for example, examine the values that are stored in ns and nl.
> Are they the same dimensions as your input image? If they are, then
> that's the reason that your 'subset' image ends up with the same
> dimensions as the input :)
>
> Cheers,
> Jeff
>
>
> gis_learner wrote:
>> Dear All,
>>
>> I am a new comer to IDL world. Moreover I am not that good at coding.
>> Thus I need your advices,
>>
>> I want to subset images via the same roi. Images are updated every 10
>> minutes or so.
>>
>> I walked through the previous answers. And they worked fine, how ever
>> the subseted image is as big as the first one.
>>
>> I will paste the code that I combined from web.
>> Any help is appreciated
>>
>> Best REgards
>>
>> pro sbst_ia_v2
>> envi, /restore_base_save_files
>> envi_batch_init, log_file='batch.txt'
>>
>> ; define the image to be opened
>> ; pixel size is a function of selevted file
>> img_file= 'C:\RSI\IDL61\products\ENVI41\data\can_tmr.img'
>> envi_open_file,image_file, r_fid=fid
>> ;print,'r_fid=',r_fid,'fid=',fid
>> print,'fid=',fid
>>
>> name='C:\RSI\IDL61\subset_via_roi\roi1.roi'
>> envi_restore_rois,name
>> roi_ids = envi_get_roi_ids(fid=r_fid)
>> roi_addr=envi_get_roi(roi_ids)
>>
>> print, 'ROI: ', name, n_elements(roi_addr)
>> ; check the roi element number
>> ;print,'name=',name, ' roi_ids=',roi_ids
>>
>> ;for j=0,0 Do begin
>> roi_data=envi_get_roi_data(roi_ids,fid=fid,pos=[0])
>> ; print, 'roi_data'
>> ;print, roi_data
>> envi_get_roi_information,roi_ids,ns=ns,nl=nl
>> print, 'ns= ',ns, '**nl=',nl
>> roi_adresses=envi_get_roi(roi_ids)
>>
>> out_data = intarr(ns,nl)
>> out_data [roi_adresses]=roi_data
>> ;print, roi_adresses
>> ; define the area to map out
>> ;yz_data=out_data[195:362,88:173]
>> envi_write_envi_file,
>> out_data,ns=ns,nl=nl,out_name='out_name',map_info=map_info
>> ;endfor
>> ;envi_batch_exit
>>
>>
>>
>>
>> end
Re: subset an image by roi in idl [message #50326 is a reply to message #50315] Mon, 25 September 2006 10:36 Go to previous messageGo to next message
Jeff N. is currently offline  Jeff N.
Messages: 120
Registered: April 2005
Senior Member
The first thing I'd suggest doing would be to clean up your code.
That's the easiest way to spot mistakes, and there are a few here you
should fix. First, you assign the filename for can_tmr.img to the
variable 'img_file', but then in the next line you try to open
'image_file' - see the difference? Also, i'm surprised this code is
even running b/c of this line:

roi_ids = envi_get_roi_ids(fid=r_fid)

The variable r_fid is undefined, as I see it. Once you get past these
things I think you'll be in a much better position to figure out for
yourself why your code isn't doing what you think it should. You
might, for example, examine the values that are stored in ns and nl.
Are they the same dimensions as your input image? If they are, then
that's the reason that your 'subset' image ends up with the same
dimensions as the input :)

Cheers,
Jeff


gis_learner wrote:
> Dear All,
>
> I am a new comer to IDL world. Moreover I am not that good at coding.
> Thus I need your advices,
>
> I want to subset images via the same roi. Images are updated every 10
> minutes or so.
>
> I walked through the previous answers. And they worked fine, how ever
> the subseted image is as big as the first one.
>
> I will paste the code that I combined from web.
> Any help is appreciated
>
> Best REgards
>
> pro sbst_ia_v2
> envi, /restore_base_save_files
> envi_batch_init, log_file='batch.txt'
>
> ; define the image to be opened
> ; pixel size is a function of selevted file
> img_file= 'C:\RSI\IDL61\products\ENVI41\data\can_tmr.img'
> envi_open_file,image_file, r_fid=fid
> ;print,'r_fid=',r_fid,'fid=',fid
> print,'fid=',fid
>
> name='C:\RSI\IDL61\subset_via_roi\roi1.roi'
> envi_restore_rois,name
> roi_ids = envi_get_roi_ids(fid=r_fid)
> roi_addr=envi_get_roi(roi_ids)
>
> print, 'ROI: ', name, n_elements(roi_addr)
> ; check the roi element number
> ;print,'name=',name, ' roi_ids=',roi_ids
>
> ;for j=0,0 Do begin
> roi_data=envi_get_roi_data(roi_ids,fid=fid,pos=[0])
> ; print, 'roi_data'
> ;print, roi_data
> envi_get_roi_information,roi_ids,ns=ns,nl=nl
> print, 'ns= ',ns, '**nl=',nl
> roi_adresses=envi_get_roi(roi_ids)
>
> out_data = intarr(ns,nl)
> out_data [roi_adresses]=roi_data
> ;print, roi_adresses
> ; define the area to map out
> ;yz_data=out_data[195:362,88:173]
> envi_write_envi_file,
> out_data,ns=ns,nl=nl,out_name='out_name',map_info=map_info
> ;endfor
> ;envi_batch_exit
>
>
>
>
> end
Re: subset an image by roi in idl [message #50481 is a reply to message #50307] Thu, 28 September 2006 23:32 Go to previous message
gis_learner is currently offline  gis_learner
Messages: 7
Registered: September 2006
Junior Member
Dear All,

Below is the code that was provided by Pete. It subsets the image based
on a EVF vector file.
I really appreciate his help and time taking to give support. Thank you
Peter.

Hoping this also helps someone.

Best Regards
pro SUBSET_by_EVF
envi, /restore_base_save_files
envi_batch_init,log_file='batch.txt'

; define the image to be opened
img_file='C:\RSI\IDL61\products\ENVI41\data\bhtmref.img'
envi_open_file,img_file,r_fid=fid
print, 'fid=',fid

; query the file and define the output file variables
envi_file_query,fid,dims=dims,ns=ns,nl=nl,nb=nb
t_fid=lonarr(nb)+fid
pos=lindgen(nb)
out_name='subset.img'

;open the EVF file
evf_fname='C:\RSI\IDL61\subset_via_roi\bhtmref.evf'
evf_id=envi_evf_open(evf_fname)

;get the vector information
envi_evf_info,evf_id,num_recs=num_recs,data_type=data_type,p rojection=projection,$
layer_name=layer_name

; print information about each record
print, 'Number of records:',num_recs
for i=0,num_recs-1 do begin
record=envi_evf_read_record(evf_id,i)
print, 'Number of nodes in Record '+strtrim(i+1,2)+':
',n_elements(record[0,*])
print, 'Record Info:'
print, record
endfor

; Get record info (assuming one record in EVF)
record=envi_evf_read_record(evf_id,0)
xMap=record[0,*]
yMap=record[1,*]

;Convert record to xy pixel coordinates of the image to be subsetted
envi_convert_file_coordinates,fid,xf,yf,xMap,yMap

;Prepare the subset dimensions
dims[0]=-1L
dims[1]=min(xf)-1
dims[2]=max(xf)-1
dims[3]=min(yf)-1
dims[4]=max(yf)-1

;Use copyfile_doit to copy input file with new dimensions
envi_doit,'cf_doit',fid=t_fid,pos=pos,dims=dims,remove=0,out _name=out_name,r_fid=r_fid

; Exit Envi
envi_batch_exit
end


Pete yazdi:
> Jeff N.
> If I understand correctly from your comment..
>
> gis_learner wrote:
>> 3) as you said the roi's are as big as the original image. I tried to
>> define ROI from the subsetted images so that I can use in the original
>> ones.. But the result is terrible.....
>
> ROI's in ENVI are referenced by pixel coordinates (not geo-coordinates)
> so if you try to use roi boundarys (dims= ) on two images with
> different x y extents (nl= | ns= ) it will not work.
>
> If you like you can email me directly, and I'll give you a hand. We
> dont want to turn this group into >> idl-pvwave-ENVI-techsupport. ;)
>
> Pete
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How can i get the co-ordinates of the peaks in a plot?
Next Topic: Re: Expanding Arrays of Structures

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

Current Time: Fri Oct 10 09:07:16 PDT 2025

Total time taken to generate the page: 1.83978 seconds