X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 27 Aug 2014 03:16 PM by  anon
Subset (resize) image with an ROI and save to disk
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:4
New Member


--
27 Aug 2014 03:16 PM
    I am having some problems. I want to load a number of images and clip out a small rectangle defined by an ROI, then save this smaller file to disk. When I subset using an ROI rather than a sub_rect, the file is not reduced (it masks the raster rather than clipping it). Is there a why to clip (subset) with an ROI? If not, is there a way to get the sub_rect from an ROI to I can subset using the sub_rect method? Here is the code I am trying to use (I cut out most of the extraneous stuff, e.g., file names, directories, etc). In the code below, if I view "smallraster" it is the region I am interested in. However, "savefile" has the full image, not clipped to the ROI. ; Use ENVI 5.1 stuff - won't work on 4.xxx ; Start ENVI e = ENVI(/CURRENT) ; Open the base file raster1 = e.OpenRaster(file1) ; Open the ROI file to set the clipping area roifile = Filepath('MlhLkCropROI.xml', ROOT_DIR = dir) rois = e.OpenRoi(roifile) savedir = 'Z:\RS_Work\IDLTest\Crop' savefile = FILEPATH('Test', ROOT_DIR = savedir) rastersmall = ENVIRaster(URI='savefile', INHERITS_FROM=raster1) rastersmall = raster1.subset(ROI=rois) rastersmall.Export, savefile, 'ENVI' END

    Deleted User



    New Member


    Posts:4
    New Member


    --
    29 Aug 2014 02:28 PM
    I am replying to my own question. I solved the problem as follows (see below) I would still like to do raster.subset(ROI=roi), but I guess it is not possible to save the file, only view the ROI subset this way. ; Open the ROI file to set the clipping area rois = e.OpenRoi(roifile) ; get the pixel associated with the ROI corners roiPixels = rois.PixelAddresses(raster1) ; this command puts all the pixels in roiPixels Xmin = min(roiPixels[0,*]) Xmax = max(roiPixels[0,*]) Ymin = min(roiPixels[1,*]) Ymax = max(roiPixels[1,*]) rastersmall = ENVIRaster(URI='savefile', INHERITS_FROM=raster1) rastersmall = raster1.subset(SUB_RECT=[Xmin,Ymin,Xmax,Ymax]) rastersmall.Export, savefile, 'ENVI'
    You are not authorized to post a reply.