Federico Carotenuto New Member
Posts:3  
18 Nov 2022 08:19 AM |
|
I am trying to perform in IDL an operation that is conceptually quite simple, but that's apparently very complicated code-wise. I have a raster with more than 200 bands. The raster data values are "float" type data and range between 0 and 1. I want to convert this raster to have "uint" data type scaled between 0 and 10000. Conceptually this would be as easy as typing "fix(raster*10000)", but that does not work, band math is needed. Now, is it really possible that this is the -only- way to apply an expression to all bands in a raster (https://www.l3harrisgeospatial.com/Support/Self-Help-Tools/Help-Articles/Help-Articles-Detail/ArtMID/10220/ArticleID/22324/How-to-use-ENVIPixelwiseBandMathRasterTask-on-all-bands-in-a-file)? It takes an insane amount of time to run and it returns an unwieldy aggregator item that's not easy to reassemble into a normal raster (task2 in the example does not work in my case, it just creates an hdr file and does not output a raster itself) and makes it complicated to do further operations on the rescaled raster (such as resizing pixel size). Is there an easier way to rescale a raster?
|
|
|
|
MariM Veteran Member
Posts:2396  
18 Nov 2022 01:52 PM |
|
You can't apply FIX to an nD raster because it is too ambiguous. Which dimensions do you want to FIX ? Also, I would use UNIT if I wanted UINT data rather than FIX. If you are wanting to apply your equation per band, then you have to extract the band from the file and apply the equation, then rebuild the band stack. This is what is going in if you use the Band Math tool in ENVI and select the option to 'Map variable to input file', which then extracts each band from the raster ('ExtractBandsFromRaster' + iterator for each band in the file), apply the equation to the band ('PixelwiseBandMathRaster' + aggregator for collecting the resulting bands), then builds the results back into a stack of bands ('BuildBandStack'). I would use ENVI's modeler to build the workflow and if you want to run from an IDL command line, use the 'Generate IDL Code' button to generate a .pro file.
|
|
|
|
Federico Carotenuto New Member
Posts:3  
21 Nov 2022 07:30 AM |
|
Thank you for the reply, I understand that probably I'm not perfectly in tune with how IDL/ENVI process data. In other softwares a raster is opened as an m*n*q cube of values and fix has no ambiguity whatsoever: I want that 3d cube turned to integer, all the values that are into it (example: https://it.mathworks.com/help/matlab/ref/fix.html). Now, if I understood that part correctly, UINT would still need some per-band processing, given that EnviCastRaster with the UINT option would scale all the values between 0 to 65,535 and not 0 to 10,000, is that correct? So in the end passing through the ENVI modeler seems like a good idea, but do you have a suggestion on how to actually do that? At the moment the tutorial I found for implementing band math in the ENVI modeler shows how to do that with a single band from a single raster or from single bands from multiple rasters, but no hints about multiple bands from the same raster (https://www.l3harrisgeospatial.com/docs/examplebandmath.html)
|
|
|
|
MariM Veteran Member
Posts:2396  
21 Nov 2022 08:00 AM |
|
All equations are going to require a per band processing. You want to apply an equation per band, not per spectrum in this case. Using an IDL (or MATLAB) command FIX or UINT is not going to stretch the data at all. It is going to convert the specified value, vector, array to integer. If a value is negative, it will be assigned a 0, not rescaled between 0-65535. ENVICastRaster is the same - it is not a stretch. As the help states: Note: Casting a floating-point raster to integer will truncate the data values. Overflow will occur when the original value is greater than the maximum value for the output data type. To set this up in Modeler, you will use the Iterator and Aggregator objects with the Band Math task as I mentioned previously. https://www.l3harrisgeospatial.com/docs/ModelerBatchProcessDataIteratorNodes.html https://www.l3harrisgeospatial.com/docs/ModelerCollectItemsAggregatorNodes.html
|
|
|
|