Skip to content

ENVI data and R

12 messages · Thomas Adams, Andrew Niccolai, PUJAN RAJ REGMI +4 more

#
Hi,

I was wondering if anyone knows how to either call up R functions from
within IDL, or conversely read ENVI image data into R.  If you have
any advice I'd greatly appreciate it.

Thanks,
Guy Serbin
#
Guy,

I don't know the answer to your question. However, depending on what you 
are trying to do, might it be possible to use GRASS GIS in place of what 
you are doing with IDL in ENVI? GRASS plays quite nicely with R. You 
probably can read ENVI image data into R, but you may need to go through 
a file conversion process to do it.

Regards,
Tom
Guy Serbin wrote:

  
    
#
This code might help:

############################################################################
####
############################################################################
####
## Read in envi file
cir.image <- "C:/YOUR_ENVI_FILE"
CIR.envi = read.ENVI(cir.image, headerfile=paste(cir.image,".hdr", sep="")) 

############################################################################
####
############################################################################
####
## Show image
CIR.envi.band1 <- CIR.envi[,,1]
image(CIR.envi.band1, main="")
mtext("Raw Matrix ENVI Image for Band 1", side=3,line = 2, font=3, cex=1.25)

############################################################################
####
############################################################################
####

Andrew Niccolai
Doctoral Candidate
Yale School of Forestry


 
-----Original Message-----
From: r-sig-geo-bounces at stat.math.ethz.ch
[mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of Guy Serbin
Sent: Tuesday, July 29, 2008 12:55 PM
To: R-sig-Geo at stat.math.ethz.ch
Subject: [R-sig-Geo] ENVI data and R

Hi,

I was wondering if anyone knows how to either call up R functions from
within IDL, or conversely read ENVI image data into R.  If you have
any advice I'd greatly appreciate it.

Thanks,
Guy Serbin
#
Thank you all for the help- I successfully read an image into R using
these methods.

I did, however, encounter some problems when loading a hyperspectral
image cube into R as it was unable to allocate the 2.9 GB of volatile
memory that it needed.

Is there a way to improve memory management by R, so that it only
reads in the data when actually needed for processing, e.g., only read
in the bands I need, or conversely read in spectra on a per-pixel
basis?

Guy

On Tue, Jul 29, 2008 at 4:05 PM, PUJAN RAJ REGMI
<regmi_pujan at hotmail.com> wrote:

  
    
#
On Tue, 29 Jul 2008, Guy Serbin wrote:

            
Buy more memory, 64-bit Linux works fine. Seriously, R is for statistics, 
so its memory management is designed for samples, even though very large 
samples can be handled when used appropriately. If your data are in a 
GeoTiff, you can read them by band using functions in the rgdal package, 
or equally well many bands in a window or tile of a larger scene. Note 
that ArcGIS uses GDAL too for handling some raster formats. Using R does 
mean thinking through your work flow.

Roger

  
    
#
My machine currently has 4 GB on it, but a lot of that's getting eaten
by video memory and the other programs I have in memory.  Also, some
of my image cubes are 12 GB in size, so I'd need to find a workaround
anyways.  However, since what my colleagues and I are interested in
are pixel-by-pixel spectral analyses, I assume the best approach would
be to pass the spectra either from ENVI/IDL (for which there is no
frontend, but I have logged a request with ITT Visual Solutions to
develop one) or conversely from ArcGIS (which can read ENVI data with
the ENVI Reader) into R for analysis.

Are you aware of ways to send arrays back and forth between R and ArcGIS?

Guy
On Tue, Jul 29, 2008 at 4:24 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:

  
    
#
R is not intended for the analysis of large hyperspectral images.
If you are interested on spectra of selected pixels, just
import the envi spectra, I recall they are stored as if
they were envi images: a raw file + a text header file in which
you have all the info you need to import into R provided you have an 
elementary knowledge of R.

In general, the approach is using RS and/or GIS software to
select from the images the information that you really have to process 
in R, which is,
as stated by Roger, a tool for statistics.

Agus
Guy Serbin wrote:

  
    
#
On Tue, 29 Jul 2008, Guy Serbin wrote:

            
You can use R as a back-end compute engine through (D)COM, see:

http://cran.r-project.org/contrib/extra/dcom/

and note the scripting sample for Python. Regular (D)COM does arrays 
easily in VBA, going through usually Python means an extra copy, but may 
be more convenient. One needs to watch error trapping and what the 
different systems do with Inf, NaN, and NA values. I usually start from 
Python in front, and both Arc and R via (D)COM, but the Duke University 
MGET site has lots of code examples for interfacing R and Arc in 
different configurations:

http://code.env.duke.edu/projects/mget

MGET is under active development.

Roger

  
    
#
Thank you for the information- I'll try that approach out.  The new
version of ENVI (4.5) is optimized to work with ArcGIS, so there may
be a way to pass spectra from ENVI to ArcGIS and then on to R if I
can't set up a direct ENVI/IDL to R connection.

I agree with you that R isn't for image processing (I certainly
enjoyed the two-three minute wait I had to endure to show a single
band ENVI image in R, something which would have been rendered
instantly in ENVI)- what we're interested in is using R for
statistical capabilities currently not available in either ENVI or
IDL.

Thanks for all your help,
Guy
On Wed, Jul 30, 2008 at 4:49 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote: