save multiple bands in one file in IDL ENVI [message #93094] |
Tue, 26 April 2016 10:03  |
Karalis Sotiris
Messages: 4 Registered: April 2016
|
Junior Member |
|
|
Dear listers
I am a novice in IDL so my question might be trivial. I have a multiple band file, and what i want to do is perform calculations with each band separately (for example, b1*10 or b2/2, not b1+b2) and then save the processed bands in one new (multiple band) file. I've been trying to use the ENVI DOIT routines. According to the manuals either ENVI LAYER STACKING DOIT or CF DOIT can accomplish what i want, but the examples don't really help me understand and adopt to my situation. Anybody has a clue? Thank you very much.
|
|
|
Re: save multiple bands in one file in IDL ENVI [message #93099 is a reply to message #93094] |
Wed, 27 April 2016 20:27   |
zacharyanorman
Messages: 17 Registered: July 2015
|
Junior Member |
|
|
I would actually use the new ENVI API which is a lot more straight forward (to me at least). You can do something like the following. You can copy/paste this into IDL and it should run if you are on the latest version and if you installed in the default installation location. Just note that if you are working with larger files then the amount of RAM on your machine might be a limiting factor. In that case, you will need to use tile iterators in ENVI.
Another thing to note is that the interleave of your raster is very important. Interleave is basically the raster dimensions which represent rows, columns, and bands. For the example below, we are band sequential (BSQ) which is [ncolumns, nrows, nbands]. I usually stick with BSQ because it is easy to work with and can be faster to use locally with custom tile iterators (5-6 times faster). I can share some code to convert file interleave if that is something you are interested in.
Hope this helps!
;start ENVI
e = envi(/current)
;the above line returns !NULL if ENVI hasn't started
;so, in that case, we start ENVI
if (e eq !NULL) then e = envi(/headless)
; Open the first input file
file = Filepath('qb_boulder_msi', ROOT_DIR=e.Root_Dir, $
SUBDIRECTORY=['data'])
msiRaster = e.OpenRaster(file)
;get the data
dat = msiRaster.GetData()
;check what the data type of dat is
;shoud see it is uint
help, dat
;pre-allocate an array with the same type as dat
;you can find what type the data is by looking up the typecode
;be careful here because IDL does automatic type promotion (i.e integers
; are promoted to floats) which doubles output file size
newDat = make_array(msiRaster.NCOLUMNS, msiRaster.NROWS, 2, TYPE=dat.typecode)
;do some band math
;fill first band of output
newDat[*,*,0] = dat[*,*,3] - dat[*,*,2]
;fill second band of output
newDat[*,*,0] = dat[*,*,2] + dat[*,*,0]
;create a new ENVIRaster
;first, specify the file output location
newRaster_uri = e.GetTemporaryFilename()
print, 'Output raster URI : "' + newRaster_uri + '"'
newraster = ENVIRaster(newDat, URI = newRaster_uri , SPATIALREF = msiRaster .SPATIALREF)
;save the output raster
newRaster.save
;make sure we close both rasters so IDL doesn't have locks on the files
newRaster.close
msiRaster.close
|
|
|
Re: save multiple bands in one file in IDL ENVI [message #93104 is a reply to message #93099] |
Thu, 28 April 2016 03:07   |
Karalis Sotiris
Messages: 4 Registered: April 2016
|
Junior Member |
|
|
Thank you Zachary. It worked just fine. I have a couple of questions more if you can help me:
1. How do i save in .tiff format (it saves in .dat)
2. How do i invoke tile operations, and lastly
3. What if i want to do this for tons of files
You see, when you begin with a new language without a tutor you don't know where to turn. So, i began with classic IDL introductions, then i read that if you want 'to include ENVI functionality' you can turn to ENVI DOIT routines (probably for those working in Remote Sensing), and then you have this 'object oriented' version of IDL-ENVI, which looks very straight forward, like you say. What to choose? By the way, can you suggest any 'getting started' tutorial, or some other reference (book or other) on this new ENVI API?
Thank you again for your help! Much appreciated.
|
|
|
|
|
|
|
Re: save multiple bands in one file in IDL ENVI [message #94217 is a reply to message #93145] |
Mon, 27 February 2017 23:46  |
carlphilip.ortiz
Messages: 1 Registered: February 2017
|
Junior Member |
|
|
Hi! I have difficulties saving each band to ASCII in ENVI. Is there a way i can use to save each band at the same time automatically? I'll send you a screenshot about my problem through mail if you can help me. Thank you! It really takes so much time saving each band one by one. Thank you again!
|
|
|