X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 14 Sep 2012 01:29 PM by  anon
Help with IDL Script to mimic ENVI "Save ROI to ASCII" type output
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:4
New Member


--
14 Sep 2012 01:29 PM
    I have a script that loops through about 400 image files and uses an ENVI ROI to select a region of interest. I use a base file for the ROIs and the following to convert for each file: ;get the vector information from base file ENVI_EVF_INFO, Evf_id, num_recs=num_recs, data_type=data_type, projection=projection, $ layer_name=layer_name ;--------------------------------------- ; create a variable to contain the records in the vector file ; for us this should be 1 record, so we just read the 0 index ; grab the xcoords of the record in Xmap, grab the ycoords in Ymap record=ENVI_EVF_READ_RECORD(Evf_id, 0) Xmap=record[0,*] Ymap=record[1,*] ; Here is a loop where we open each file for application ... snipped for brevity ; We open the file (fid) and do a few things, then extract the ROI defined by Xmap and Ymap ENVI_FILE_QUERY, fid, DIMS =dims, ns=Ons, NB=Onb, nl=Onl, DATA_TYPE=Odata_type ; Get the dimensions of the file ENVI_CONVERT_FILE_COORDINATES,fid, xf, yf, Xmap, Ymap ; convert the lat long of the ROI to the pixels of the file dims[0]=-1L ; type of dimensions long float dims[1]=min(xf)-1 ; left x corner - 0 based dims[2]=max(xf)-1 ; right x corner - 0 based dims[3]=min(yf)-1 ; lower y corner dims[4]=max(yf)-1 ; upper y corner ; Use routine to write an ASCII file using just a portion (dims) of the input (fid) with pos (6) bands out_name = 'i:\IDLTest\OutPut\x'+ namefile +'_' + string(counter,FORMAT='(I2.2)') ; setup output file - new directory ENVI_OUTPUT_TO_EXTERNAL_FORMAT, /ASCII, dims=dims, OUT_NAME=out_name, fid=fid, pos=pos This is what I want to change. The ROI is small (either 3x3 9 pixels, or 5x5 25 pixels). The above commands work well but puts the data out in like an image. We are using the data in another program and would like to have the output look like the ENVI menu command "Save ROI to ASCII". For each point in the ROI you get a line like: # Date Time x y Lat Long Band1 Band2 Band3 Band4 Band 5 Band 6 This might not be the exact order - but is close I'm away from my machine right now. Is there an easy way to duplicate this in IDL? I looked for an ENVI_DO_IT command, but didn't find anything close. Gus

    Deleted User



    New Member


    Posts:
    New Member


    --
    17 Sep 2012 09:39 AM
    I think what you are going to need here is to write out to a text file and then format the outputs accordingly. The formatting can be a bit tedious so the best approach is to print to the output console first to see how it looks and then print to the file. Try it with one image first to make each test quicker. Consider the following snippets from some code, please note that the xmap/ymap may or may not exactly apply for your situation: ;Set up an output *.txt file to print the results to... out_file =dialog_pickfile(/write, filter='*.txt', /default_extension) if (out_file eq '') then return openw, lun, out_file, /get_lun ;Now go to each point (lon, lat) for i=0, n_elements(xf)-1 do begin print,'' printf,lun,'' print,'Location',[i+1],'Lon/Lat:',ixmap[i], iymap[i] printf,lun,'Location',[i+1],' Lon/Lat:',ixmap[i], iymap[i] ;Get the pixel values at each point for k=0, nb-1 do begin dims = ([0 ,xf[i] , xf[i] , yf[i] , yf[i]]) p_value= envi_get_data(fid=fid, pos=pos[k], dims=dims) print,k+1,p_value, format='("Band number:",i5," ","Pixel value: ",3f0)' printf,lun,k+1,p_value, format='("Band number:",i5," ","Pixel value: ",3f0)' endfor ; for pixel values endfor ;for xf file coordinates
    You are not authorized to post a reply.