X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 14 Jul 2008 12:29 PM by  anon
Creating ROIs and using them in IDL
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
14 Jul 2008 12:29 PM
    Hi all, I have a problem with the following code. I want to create an ROI by band threshold, convert the ROI into a class image, and then sieve the class image. I am able to do this perfectly using the ENVI GUI. However, I want to do this in an IDL script and am able to create the ROI, but am not able to proceed further. I think i'm messing up the ROI_IDS concept and that maybe the problem. But i'm not quite sure. I am basically following the same steps as i would when i use the GUI. Another thing: My input data has some NaN values. When the ROI is created, i get the following error. Program caused arithmetic error: Floating illegal operand I may need to use the NaN keyword, but there isn't one for these. The ROI overlays ok though. Here's the code. :*********************************************************** pro example_roi_thresh_doit ;First restore all the base save files. ; envi, /restore_base_save_files ; Initialize ENVI and send all errors and warnings to the file batch.txt ; envi_batch_init, log_file='batch.txt' ; Open the input file forward_function envi_get_roi_ids envi_open_file, 'D:\trial\2004_meltdate.dat', r_fid=fid if (fid eq -1) then begin envi_batch_exit return endif ; ; Use the POS keyword to select the first band ; to use for the ROI. envi_file_query, fid, dims=dims, ns=ns, nl=nl pos = [0] roi_name = 'test ROI' output_path='D:\' out_name = output_path+'test.roi' ; ; Perform the ROI threshold envi_doit, 'roi_thresh_doit', fid=fid, pos=pos, dims=dims, max_thresh=170, min_thresh=100,$ roi_color=5, roi_name=roi_name, roi_id=roi_id ;Get the ROI ID(s) roi_ids=envi_get_roi_ids(fid=fid) ;Create a class image from the resulting ROI class_values =[1] print,class_values outroi=output_path + 'roi.dat' envi_doit,'ENVI_ROI_TO_IMAGE_doit',class_values=1,fid=fid,roi_ids=roi_ids,out_name=outroi,r_fid=classid ;Create a sieve image from the above class image outsieve=output_path+'sieve.dat' envi_doit,'class_cs_doit',dims=dims,fid=classid,method=1,sieve_min=3,pos=0,out_name=outsieve,r_fid=classed ; Exit ENVI ; envi_batch_exit end ;******************************************************************************* Could you please point out the error(s) in the above code ? Thank you very much, Raghu

    Deleted User



    New Member


    Posts:
    New Member


    --
    14 Jul 2008 12:29 PM
    I think you're right about being a little confused about the ROI_ID concept. When you call ROI_THRESH_DOIT, you set an output keyword named ROI_ID (*not* ROI_IDS). So you're telling that routine to store the id for the ROI it creates in the variable ROI_ID. But you don't use that id later in your code when you call ENVI_ROI_TO_IMAGE_DOIT. Instead, you call ENVI_GET_ROI_IDS and get a list of all ROI's there are (which may be just the ROI you created by thresholding, but it might also be more). You store that list in the variable ROI_IDS (not ROI_ID) and then feed that variable's contents into ENVI_ROI_TO_IMAGE_DOIT. So I what i think you should do is get rid of the call to ENVI_GET_ROI_IDS and change your call to ENVI_ROI_TO_IMAGE_DOIT to this: envi_doit,'ENVI_ROI_TO_IMAGE_doit',class_values=1,fid=fid,roi_ids=roi_id, $ out_name=outroi,r_fid=classid See the difference? This way you're feeding the roi-to-image routine the output from the thresholding routine, which i think is what you want to do. Jeff

    Deleted User



    New Member


    Posts:
    New Member


    --
    25 May 2012 06:42 AM
    Hello all, I have another problem while using ROI_THRESH_DOIT'. I get error msg: 'Unable to allocate memory to make array'. This is because there are many pixes in one threshold range and then RAM fails to handle such a long array. Does some one has some idea how to handle it, I also changed in the configuration file but it doesnt help much. I want to do supervised classification. I also tried with polygon roi by create and define but may be I am not doing it right. envi_open_data_file, 'test.img', r_fid=fid if (fid eq -1) then begin envi_batch_exit return endif envi_file_query, fid, dims=dims, nb=nb roi_id1 = envi_create_roi(color=4, name='roi1', ns=ns, nl=nl) xpts = [8406,9226,8406,9226] ypts = [7688,7688,8559,8559] envi_define_roi, roi_id1, /polygon, xpts=xpts, ypts=ypts roi_id2 = envi_create_roi(color=3, name='roi2', ns=ns, nl=nl) xpts = [3486,4203,3486,4203] ypts = [6714,6714,8149,8149] envi_define_roi, roi_id2, /polygon, xpts=xpts, ypts=ypts roi_id3 = envi_create_roi(color=2, name='roi3', ns=ns, nl=nl) xpts = [5486,4203,5486,4203] ypts = [6714,6714,9149,9149] envi_define_roi, roi_id3, /polygon, xpts=xpts, ypts=ypts roi_ids = envi_get_roi_ids(fid = fid) print, 'ROI: ', n_elements(roi_ids) It always give 1 roi only, but I need all defined rois to use them as a traininng set for classification.. Can some one correct me, in creating rois for different classes I need. Hope to get your support. Thanks a million.. Alka
    You are not authorized to post a reply.