comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » envi_get_data
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
envi_get_data [message #58173] Mon, 21 January 2008 11:42 Go to next message
yychongzi is currently offline  yychongzi
Messages: 6
Registered: September 2007
Junior Member
Hi, I am writing a program to calcualte a new image from an old one.
But I always get error about the envi_get_data.

The message reads:
% Variable is undefined: POS.
% Execution halted at: ENVI_GET_DATA

I got the same message even when I did not put 'pos=pos' in the
envi_get_data statement.

Thanks a lot. Here is the code:

pro cal
envi, /restore_base_save_files
envi_init, /batch_mode
envi_open_file,'E:\image1999',r_fid=fid
if (fid eq -1) then return
envi_file_query, fid, ns=ns, nl=nl, nb=nb, pos=pos ,dims=dims
image=fltarr(nb,nl,ns)
image2=fltarr(nb,nl,ns)
image = envi_get_data (fid=fid,dims=dims, pos =pos)
For i=0, nb-1 Do Begin
For j=0,nl-1 Do Begin
For k=0,ns-1 Do Begin
image2[i,j,k]=image[i,j,k]* 0.8 + 100
Endfor
Endfor
Endfor
ENVI_WRITE_ENVI_FILE,image2,data_type=2,nb=nb,nl=nl,ns=ns, out_name='E:
\test.img'
END
Re: envi_get_data [message #58273 is a reply to message #58173] Fri, 25 January 2008 06:03 Go to previous messageGo to next message
lbusett@yahoo.it is currently offline  lbusett@yahoo.it
Messages: 30
Registered: February 2006
Member
Hi,

I don't know if it will solve all your problems, but I believe that
you should replace the instruction:

> image2=fltarr((nb,nl,ns)

with:

image2 = fltarr (nb, ns, nl)

because ENVI_GET_DATA returns an array in samples by lines order (see
the help). (Obviously, if you have a square image nothing will change)

You can also remove the instruction

> image=fltarr((nb,nl,ns)

since the "image" variable is overwritten by the "envi_get_data"
instruction.

Hope this helps,

Lorenzo

On 23 Gen, 22:57, yychon...@gmail.com wrote:
> Thank you Jean. I did correct the error you pointed out, and I found
> something werid for the output image. I used a 2bands input file and
> the output image seems twist and even does not have the correct
> boundary shape, and the data was wrong.
>
> Then I tested it with a one band input image, when I tried to multiply
> the input image by a constant to get a new image(my output) it did not
> work (it did not get the image that supposed to). If I just add the
> input image with a small number, it works fine. But if I add the image
> with a large number, like 35000(the min. data on the input image is
> -32768), then it went wrong again.
>
> I thought it might be due to the format of the image, then I changed
> fltarr to dblarr, it still wont give the right output image.
>
> Many thanks.
>
> Now my code looks like this:
>
> pro cal
> envi, /restore_base_save_files
> envi_init, /batch_mode
> envi_open_file,'F:\testinput.img',r_fid=fid
> if (fid eq -1) then return
> envi_file_query, fid, ns=ns, nl=nl, nb=nb, data_type=data_type
> map_info = envi_get_map_info(fid = fid)
> dims = [-1L, 0, ns - 1, 0, nl - 1]
> pos=lindgen(nb)
> image=fltarr((nb,nl,ns)
> image2=fltarr((nb,nl,ns)
> For i=0, nb-1 Do Begin
> image = envi_get_data (fid=fid,dims=dims,pos=i)
> image2[i,*,*]=image
> Endfor
> ENVI_WRITE_ENVI_FILE,image2,data_type=data_type,nb=nb,nl=nl, ns=ns,map_info
> = map_info, $
> out_name='F:\testoutput.img'
> END
>
> On Jan 21, 3:00 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
> wrote:
>
>>> envi_file_query, fid, ns=ns, nl=nl, nb=nb, pos=pos ,dims=dims
>
>> ... in the help file, there is no POS keyword in this function... so
>> later on, when you try to use it, pos is undefined.
>
>> Jean
Re: envi_get_data [message #58355 is a reply to message #58173] Fri, 25 January 2008 13:49 Go to previous messageGo to next message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
yychongzi@gmail.com wrote:
> Thank you Lorenzo and Pete.
>
> Pete, you are right on the datatype. My input file is integer, it has
> to be changed. Now the program runs just fine :)
>
> By the way, I have another question:
> I used ENVI to do layer stacking, sometimes I got a big .ige file and
> a small .img file, sometimes, more often, I got a big .img file with a
> small .rrd file. I dont know why and the difference.
>
> Thank you guys again.

From Envi Help file:

ERDAS IMAGINE 8.x image files larger than 2 GB use a raster spill file
to store the data from large data sets. That is, images larger than 2 GB
are defined by two files: header information is stored in the .img file,
and the image data is stored in a second file with the same root name
using an .ige extension.

Now, the .rrd is an overview of your data..
Jean
Re: envi_get_data [message #58357 is a reply to message #58173] Fri, 25 January 2008 13:25 Go to previous messageGo to next message
yychongzi is currently offline  yychongzi
Messages: 6
Registered: September 2007
Junior Member
Thank you Lorenzo and Pete.

Pete, you are right on the datatype. My input file is integer, it has
to be changed. Now the program runs just fine :)

By the way, I have another question:
I used ENVI to do layer stacking, sometimes I got a big .ige file and
a small .img file, sometimes, more often, I got a big .img file with a
small .rrd file. I dont know why and the difference.

Thank you guys again.

On Jan 25, 10:18 am, Pete <peter.e...@shaw.ca> wrote:
> Hi,
> Typical ENVI format files are "usually" band sequential:
> Array=fltarr(ns, nl, nb) as its quickest to display.
> You can obtain the interleave within the ENVI_FILE_QUERY with the
> keyword Interleave=interleave where bsq=0, bil=1 and bip=2 - or by
> looking at the header.  Next I would check the datatype of your input
> file. In your code you read in the file, query the datatype create a
> new float array then write the file with the datatype of your input.
> What if your input was byte or integer?  Since you're output is float
> you could hardcode the data_type=4 (or 5 for double).
>
> For example you could do the following:
>
> pro cal
> envi, /restore_base_save_files
> envi_init, /batch_mode
> envi_open_file,'F:\testinput.img',r_fid=fid
> if (fid eq -1) then return
> envi_file_query, fid, ns=ns, nl=nl, nb=nb, data_type=data_type,  $
>      interleave=interleave, dims=dims
>     ;Could have an "if" statement to check and set the interleave
> map_info = envi_get_map_info(fid = fid)
> ;dims = [-1L, 0, ns - 1, 0, nl - 1]  **you can get the dimensions from
> the query above
> pos=lindgen(nb)
> image=fltarr(ns, nl, nb) ; storage array for multi band processing
> (loop over bands)
> ;image2=fltarr((nb,nl,ns) ** not required
> For i=0, nb-1 Do Begin
>      ;read band and convert to float
>      inBand = Float(envi_get_data (fid=fid,dims=dims,pos=i)) ;read the
> 2d array
>      image[*,*,i]=inBand* 0.8 + 100   ;do processing and store in
> array
> Endfor
> ENVI_WRITE_ENVI_FILE,image,data_type=4,nb=nb,nl=nl,ns=ns,map _info=
> map_info, $
> out_name='F:\testoutput.img'
> END
>
> With this method you may run into memory problems, as you are reading
> by entire bands and storing the whole image.  When the image gets
> larger you will have to look into ENVI's tiling routines.
>
> Hopefully this gets you started,
>
> Pete
Re: envi_get_data [message #58369 is a reply to message #58273] Fri, 25 January 2008 09:18 Go to previous messageGo to next message
peter.eddy@shaw.ca is currently offline  peter.eddy@shaw.ca
Messages: 19
Registered: March 2005
Junior Member
Hi,
Typical ENVI format files are "usually" band sequential:
Array=fltarr(ns, nl, nb) as its quickest to display.
You can obtain the interleave within the ENVI_FILE_QUERY with the
keyword Interleave=interleave where bsq=0, bil=1 and bip=2 - or by
looking at the header. Next I would check the datatype of your input
file. In your code you read in the file, query the datatype create a
new float array then write the file with the datatype of your input.
What if your input was byte or integer? Since you're output is float
you could hardcode the data_type=4 (or 5 for double).

For example you could do the following:

pro cal
envi, /restore_base_save_files
envi_init, /batch_mode
envi_open_file,'F:\testinput.img',r_fid=fid
if (fid eq -1) then return
envi_file_query, fid, ns=ns, nl=nl, nb=nb, data_type=data_type, $
interleave=interleave, dims=dims
;Could have an "if" statement to check and set the interleave
map_info = envi_get_map_info(fid = fid)
;dims = [-1L, 0, ns - 1, 0, nl - 1] **you can get the dimensions from
the query above
pos=lindgen(nb)
image=fltarr(ns, nl, nb) ; storage array for multi band processing
(loop over bands)
;image2=fltarr((nb,nl,ns) ** not required
For i=0, nb-1 Do Begin
;read band and convert to float
inBand = Float(envi_get_data (fid=fid,dims=dims,pos=i)) ;read the
2d array
image[*,*,i]=inBand* 0.8 + 100 ;do processing and store in
array
Endfor
ENVI_WRITE_ENVI_FILE,image,data_type=4,nb=nb,nl=nl,ns=ns,map _info=
map_info, $
out_name='F:\testoutput.img'
END

With this method you may run into memory problems, as you are reading
by entire bands and storing the whole image. When the image gets
larger you will have to look into ENVI's tiling routines.

Hopefully this gets you started,

Pete
Re: envi_get_data [message #67987 is a reply to message #58173] Tue, 15 September 2009 00:12 Go to previous messageGo to next message
woods1 is currently offline  woods1
Messages: 24
Registered: August 2009
Junior Member
On 14 Sep., 20:59, Robert <robert.m...@gmail.com> wrote:
> On Sep 14, 11:07 am, woods1 <merria...@yahoo.fr> wrote:
>
>> Hi,
>> I have a problem. I want to display an image an d i do this:
>
>> imag = make_array(ns, nl) ; with ns=21815 and nl=10636
>
>> imag = envi_get_data(fid=fid, dims=dims, pos=pos)
>
>> but i become an error message '" Unable to allocate memory: to make
>> array."
>
>> can somebody help me?
>
>> thanks in advance
>
>> Woods
>
> First, do not preallocate the image array; i.e. remove the MAKE_ARRAY
> line. That might solve your problem right there. If you still get the
> error you should probably use the DIMS keyword to read only a subset.

thank you, thank you!
thanks of your help!
Re: envi_get_data [message #67989 is a reply to message #58173] Mon, 14 September 2009 11:59 Go to previous messageGo to next message
Robert Moss, PhD is currently offline  Robert Moss, PhD
Messages: 29
Registered: November 2006
Junior Member
On Sep 14, 11:07 am, woods1 <merria...@yahoo.fr> wrote:
> Hi,
> I have a problem. I want to display an image an d i do this:
>
> imag = make_array(ns, nl) ; with ns=21815 and nl=10636
>
> imag = envi_get_data(fid=fid, dims=dims, pos=pos)
>
> but i become an error message '" Unable to allocate memory: to make
> array."
>
> can somebody help me?
>
> thanks in advance
>
> Woods

First, do not preallocate the image array; i.e. remove the MAKE_ARRAY
line. That might solve your problem right there. If you still get the
error you should probably use the DIMS keyword to read only a subset.
Re: envi_get_data [message #68141 is a reply to message #58173] Fri, 02 October 2009 06:29 Go to previous messageGo to next message
Andrew Rodger is currently offline  Andrew Rodger
Messages: 5
Registered: October 2009
Junior Member
On Oct 2, 12:48 am, woods1 <merria...@yahoo.fr> wrote:
> On 29 Sep., 15:05, woods1 <merria...@yahoo.fr> wrote:
>
>> Hi,
>>  i have a problem.
>> i try this: img = envi_get_data(fid=De_fid, dims=dims,pos=pos), but i
>> obtain this error : "Unsble to allocate memory; to make array"
>> my image is big. ns=36800 , nl=57600.
>> i want to display  tihs image.
>
>> can somebody help me?
>> thank you in advence
>
>> Woods
>
> Thank you an all.
> I have to reduce an image with envi_get_data(dims = dims, fid=file ID
> [, INTERP={0 | 1 | 2 | 3}], POS=long integer [, XFACTOR=integer] [,
> YFACTOR=integer])

I am not sure if it applies but I think there is also an IDL object
called IDLgrImage that handles displays for large imagery (assuming
you are not wanting to display it all at once) and I think it only
loads as much of the image as required and thus reduces the memory
requirements. May also handle zoom type stuff as well.
Re: envi_get_data [message #68148 is a reply to message #58173] Thu, 01 October 2009 09:48 Go to previous messageGo to next message
woods1 is currently offline  woods1
Messages: 24
Registered: August 2009
Junior Member
On 29 Sep., 15:05, woods1 <merria...@yahoo.fr> wrote:
> Hi,
>  i have a problem.
> i try this: img = envi_get_data(fid=De_fid, dims=dims,pos=pos), but i
> obtain this error : "Unsble to allocate memory; to make array"
> my image is big. ns=36800 , nl=57600.
> i want to display  tihs image.
>
> can somebody help me?
> thank you in advence
>
> Woods

Thank you an all.
I have to reduce an image with envi_get_data(dims = dims, fid=file ID
[, INTERP={0 | 1 | 2 | 3}], POS=long integer [, XFACTOR=integer] [,
YFACTOR=integer])
Re: envi_get_data [message #68164 is a reply to message #58173] Wed, 30 September 2009 07:34 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
woods1 writes:

> I don't no how many bytes are in the image. The dimension of image is
> 36800x57600

Multiplying those two numbers together might give you
a ballpark figure. My guess is you would then have to
multiply that result by 2 or 4 to come up with the
actual number. But something in the range of 2-8 Gigabytes
would be my best guess.

That seems a little, uh, largish to put into a single
IDL variable. I'm guessing you don't have one of those nifty
machines with a 64-bit operating system and 100 GBytes of
RAM, probably. :-(

And where do you intend to display it? Have you rented
out the giant screen on Times Square? Have you given
any thought to the resolution of your display? What do
you suppose you would actually see if you *could* display
this image?

I know you are complaining about all the *processing*
that has to occur. But maybe it would be a good idea
to start with more *thinking* about the problem.

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: envi_get_data [message #68165 is a reply to message #58173] Wed, 30 September 2009 07:14 Go to previous messageGo to next message
woods1 is currently offline  woods1
Messages: 24
Registered: August 2009
Junior Member
On 30 Sep., 11:39, Allard de Wit <allard.de...@wur.nl> wrote:
> woods1 wrote:
>> Hi,
>>  i have a problem.
>> i try this: img = envi_get_data(fid=De_fid, dims=dims,pos=pos), but i
>
> Hi,
>
> Using ENVI_Get_Data() on such large images is really a bad idea.
> Trying to read the whole image will take more then 2Gb of memory (in
> case of 8bit data) and you will have trouble to fit it in memory on
> any 32 bit operating system.
>
> What you should do instead is use ENVI's tiling mechanism to read your
> image in chunks and loop over the number of tiles. Then resample each
> tile to be able to display it (or do whatever processing you want) and
> stitch the results together. So in pseudo code it should look like
> this:
>
> tile_ID = ENVI_Init_Tile(File_ID, NUM_TILES=num_tiles,
> INTERLEAVE=1, ....)
> FOR i=0L, num_tiles-1 DO BEGIN
>      data = ENVI_Get_Tile(tile_ID)
>      <processing data goes here>
> ENDFOR
> ENVI_Tile_Done, tile_ID
>
> Setting INTERLEAVE=1 ensures that you read your file line by line. It
> may be more efficient to use INTERLEAVE=0 but then you need to write
> some logic that handles the size of the tile that ENVI_Get_Tile
> returns, which depends on you memory settings.
>
> Hope this helps.
>
> Allard

My question is, what are the processing data here, when i will display
an image?

thank you
Re: envi_get_data [message #68168 is a reply to message #58173] Wed, 30 September 2009 02:39 Go to previous messageGo to next message
wita is currently offline  wita
Messages: 43
Registered: January 2005
Member
woods1 wrote:
> Hi,
> i have a problem.
> i try this: img = envi_get_data(fid=De_fid, dims=dims,pos=pos), but i

Hi,

Using ENVI_Get_Data() on such large images is really a bad idea.
Trying to read the whole image will take more then 2Gb of memory (in
case of 8bit data) and you will have trouble to fit it in memory on
any 32 bit operating system.

What you should do instead is use ENVI's tiling mechanism to read your
image in chunks and loop over the number of tiles. Then resample each
tile to be able to display it (or do whatever processing you want) and
stitch the results together. So in pseudo code it should look like
this:

tile_ID = ENVI_Init_Tile(File_ID, NUM_TILES=num_tiles,
INTERLEAVE=1, ....)
FOR i=0L, num_tiles-1 DO BEGIN
data = ENVI_Get_Tile(tile_ID)
<processing data goes here>
ENDFOR
ENVI_Tile_Done, tile_ID

Setting INTERLEAVE=1 ensures that you read your file line by line. It
may be more efficient to use INTERLEAVE=0 but then you need to write
some logic that handles the size of the tile that ENVI_Get_Tile
returns, which depends on you memory settings.

Hope this helps.

Allard
Re: envi_get_data [message #68171 is a reply to message #58173] Wed, 30 September 2009 01:25 Go to previous messageGo to next message
woods1 is currently offline  woods1
Messages: 24
Registered: August 2009
Junior Member
On 29 Sep., 15:18, David Fanning <n...@dfanning.com> wrote:
> woods1 writes:
>> i try this: img = envi_get_data(fid=De_fid, dims=dims,pos=pos), but i
>> obtain this error : "Unsble to allocate memory; to make array"
>> my image is big. ns=36800 , nl=57600.
>> i want to display  tihs image.
>
>> can somebody help me?
>
> Probably not. How many bytes, do you suppose,
> are in that image?
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

I don't no how many bytes are in the image. The dimension of image is
36800x57600
Re: envi_get_data [message #68172 is a reply to message #58173] Wed, 30 September 2009 01:09 Go to previous messageGo to next message
woods1 is currently offline  woods1
Messages: 24
Registered: August 2009
Junior Member
On 30 Sep., 10:02, woods1 <merria...@yahoo.fr> wrote:
> On 29 Sep., 16:40, Chris Jengo <cje...@gmail.com> wrote:
>
>> Display where?  If you want an ENVI display, take a look at
>> ENVI_DISPLAY_BANDS.  Displaying in your own draw widget will take some
>> special effort.
>
>> Chris
>
> I have used at all times envi_get_data, but her i have a big image and
> i don't no what i can do.
> when i do envi_display_bands,i obtain an envi display, but this is no
> my anbition.
> I want to reurns a spatial image data from file.

I have used at all times envi_get_data, but her i have a big image
and
i don't no what i can do.
when i do envi_display_bands,i obtain an envi display, but this is no
my anbition.
I want to reurns a spatial image data from file.
Re: envi_get_data [message #68173 is a reply to message #58173] Wed, 30 September 2009 01:02 Go to previous messageGo to next message
woods1 is currently offline  woods1
Messages: 24
Registered: August 2009
Junior Member
On 29 Sep., 16:40, Chris Jengo <cje...@gmail.com> wrote:
> Display where?  If you want an ENVI display, take a look at
> ENVI_DISPLAY_BANDS.  Displaying in your own draw widget will take some
> special effort.
>
> Chris

I have used at all times envi_get_data, but her i have a big image and
i don't no what i can do.
when i do envi_display_bands,i obtain an envi display, but this is no
my anbition.
I want to reurns a spatial image data from file.
Re: envi_get_data [message #68179 is a reply to message #58173] Tue, 29 September 2009 07:40 Go to previous messageGo to next message
Chris Jengo is currently offline  Chris Jengo
Messages: 13
Registered: July 1999
Junior Member
Display where? If you want an ENVI display, take a look at
ENVI_DISPLAY_BANDS. Displaying in your own draw widget will take some
special effort.

Chris
Re: envi_get_data [message #68182 is a reply to message #58173] Tue, 29 September 2009 06:18 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
woods1 writes:

> i try this: img = envi_get_data(fid=De_fid, dims=dims,pos=pos), but i
> obtain this error : "Unsble to allocate memory; to make array"
> my image is big. ns=36800 , nl=57600.
> i want to display tihs image.
>
> can somebody help me?

Probably not. How many bytes, do you suppose,
are in that image?

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: envi_get_data [message #82024 is a reply to message #58173] Mon, 12 November 2012 14:02 Go to previous message
lefsky@gmail.com is currently offline  lefsky@gmail.com
Messages: 13
Registered: June 2010
Junior Member
On Sunday, November 11, 2012 7:54:38 PM UTC-7, lef...@gmail.com wrote:
> I am trying to extract a spatial subset of a compressed file from within an envi program. envi_get_data returns an array of the appropriate size and data type, but the values within the array aren't meaningful. Extracting the same data from within the ENVI gui results in correct data.
>
>
>
> Is this a problem that arises from compression or should I be looking elsewhere for a solution?

I have solved the problem, sort of. What I did is translate the code to the new envi API and it worked right away.
Re: envi_get_data [message #82038 is a reply to message #58173] Sun, 11 November 2012 20:22 Go to previous message
lefsky@gmail.com is currently offline  lefsky@gmail.com
Messages: 13
Registered: June 2010
Junior Member
On Sunday, November 11, 2012 7:54:38 PM UTC-7, lef...@gmail.com wrote:
> I am trying to extract a spatial subset of a compressed file from within an envi program. envi_get_data returns an array of the appropriate size and data type, but the values within the array aren't meaningful. Extracting the same data from within the ENVI gui results in correct data.
>
>
>
> Is this a problem that arises from compression or should I be looking elsewhere for a solution?

To clarify, the compressed file is an envi file
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Beginner: Oplot line t^(-5/3)
Next Topic: Curve Fitting Question

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:22:16 PDT 2025

Total time taken to generate the page: 0.00516 seconds