Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.idl-pvwave

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-21-2009, 09:45 PM
Hassan
Guest
 
Posts: n/a
Default ENVI's codes

I wonder if we can have an access to source code of ENVI functions?
I need to export some images from ENVI to IDL, I can use the export-
varaible-to-idl function in ENVI but I want to know how I can do this
without using ENVI.
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 11-21-2009, 10:23 PM
Michael Galloy
Guest
 
Posts: n/a
Default Re: ENVI's codes

Hassan wrote:
> I wonder if we can have an access to source code of ENVI functions?
> I need to export some images from ENVI to IDL, I can use the export-
> varaible-to-idl function in ENVI but I want to know how I can do this
> without using ENVI.


No, ENVI is not open source.

Do you just want to be able to read some ENVI files in IDL? That is
fairly straight-forward; the data file is just a binary file which the
associated header file describes.

Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
Reply With Quote
  #3 (permalink)  
Old 11-21-2009, 10:26 PM
chris
Guest
 
Posts: n/a
Default Re: ENVI's codes

On 22 Nov., 00:23, Michael Galloy <mgal...@gmail.com> wrote:
> Hassan wrote:
> > I wonder if we can have an access to source code of ENVI functions?
> > I need to export some images from ENVI to IDL, I can use the export-
> > varaible-to-idl function in ENVI but I want to know how I can do this
> > without using ENVI.

>
> No, ENVI is not open source.
>
> Do you just want to be able to read some ENVI files in IDL? That is
> fairly straight-forward; the data file is just a binary file which the
> associated header file describes.
>
> Mike
> --www.michaelgalloy.com
> Research Mathematician
> Tech-X Corporation


You can also try to export your envi-data as geotiff which can be
imported to idl by read_tiff with the geotiff flag. Give it a try. If
this won't work for you, just think about what Michael said...

Regards

CR
Reply With Quote
  #4 (permalink)  
Old 11-22-2009, 05:41 PM
Hassan
Guest
 
Posts: n/a
Default Re: ENVI's codes

I used the following code to read an ENVI file into IDL:


imagesize=[488,290,62]
refImage = READ_BINARY(file, DATA_DIMS = imageSize)
DEVICE, DECOMPOSED = 0
LOADCT, 38
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1]
TV, refImage, 0

but the resulting display was strange. I don't know how to put an
image here since it's easier to explain. anyway, the resulting display
seems to show a superimposed of the features. for example if in the
original image there are 2 features which are a bit far from each
other but when I want to display it in the IDL those two features are
overlaid.


Reply With Quote
  #5 (permalink)  
Old 11-22-2009, 08:35 PM
Hassan
Guest
 
Posts: n/a
Default Re: ENVI's codes


I used the following code to display the image:
image=read_tiff(file)
imagesize=[62,488,290]
DEVICE, DECOMPOSED = 0
LOADCT, 38
WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2]
TV, Image(0,*,*), 0

but there are two problems: first it's displayed upside-down and
second the way it shows the image is quite different with other
softwares like ENVI, it's more like the image is shown in 256-color
table or something like that.

Reply With Quote
  #6 (permalink)  
Old 11-22-2009, 11:18 PM
Jiek
Guest
 
Posts: n/a
Default Re: ENVI's codes

On Nov 23, 5:35*am, Hassan <hkhav...@gmail.com> wrote:
> I used the following code to display the image:
> image=read_tiff(file)
> imagesize=[62,488,290]
> DEVICE, DECOMPOSED = 0
> LOADCT, 38
> WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2]
> TV, Image(0,*,*), 0
>
> but there are two problems: first it's displayed upside-down and
> second the way it shows the image is quite different with other
> softwares like ENVI, it's more like the image is shown in 256-color
> table or something like that.


I found a function to read ENVI image and it work well.As follows:
pro read_envi_image, infile, img, xs, ys, type, offset, mapinfo

;
; Copyright (c) 2003,Institute of Photogrammetry and Remote Sensing, ;
(IPF),
; Technical University of Vienna. Unauthorised reproduction
prohibited.
;
;+
; NAME:
; read_envi_file
;
; PURPOSE:
; IDL program, which reads standard ENVI image files (*.img).
;
;
; CATEGORY:
; Input_Output
;
; CALLING SEQUENCE:
; read_envi_file, infile, img, xs, ys, type,offset
;
; INPUTS:
; infile - input file name
;
; OPTIONAL INPUTS:
; None
;
; KEYWORD PARAMETERS:
; None
;
; OUTPUTS:
; img - ENVI image file, 2D array
; xs - number of samples
; ys - number of lines
; type - image data type
; offset - headeroffset
; mapinfo - information on spatial resolution (spacing) and
coordinates
; of upper left corner (ulx, uly)
;
;
; OPTIONAL OUTPUTS:
; None
;
; COMMON BLOCKS:
; none
;
; SIDE EFFECTS:
;
; RESTRICTIONS:
; None
;
; PROCEDURE:
;
; EXAMPLE:
;
; REMARKS
; None
;
; MODIFICATION HISTORY:
; Written by: Carsten Pathe, cp@ipf.tuwien.ac.at
; Date: 25.08.2003
;
;-

image = infile

header = strsplit(infile,'.',/extract)
header = header(n_elements(header)-2)+'.hdr'

openr, unit, header, /get_lun

header_line = ''

while not eof(unit) do begin

readf, unit, header_line
tmp = strsplit(header_line(0), '=', /extract)
header_keyword = strsplit(tmp(0), ' ', /extract)

print, header_keyword

if header_keyword(0) eq 'samples' then xs = long(tmp(1))
if header_keyword(0) eq 'lines' then ys = long(tmp(1))
if header_keyword(0) eq 'header' then offset = long(tmp(1))
if header_keyword(0) eq 'data' then type = long(tmp(1))

if header_keyword(0) eq 'map' then begin

mapinfo_tmp=strsplit(tmp(1),'{',/extract)
mapinfo_tmp=strsplit(mapinfo_tmp(1),',',/extract)

mapinfo={ulx:0.,uly:0.,spacing:0.}
mapinfo.ulx=mapinfo_tmp(3)
mapinfo.uly=mapinfo_tmp(4)
mapinfo.spacing=mapinfo_tmp(5)

endif

endwhile

close,unit & free_lun, unit
print, xs, ys

if type eq 1 then img=bytarr(xs, ys)
if type eq 2 then img=intarr(xs, ys)
if type eq 4 then img=fltarr(xs, ys)
if type eq 12 then img=uintarr(xs, ys)

openr, unit,image, /get_lun
point_lun, unit, offset
readu, unit, img
close, unit & free_lun, unit

end

Reply With Quote
  #7 (permalink)  
Old 11-22-2009, 11:27 PM
Jeff N.
Guest
 
Posts: n/a
Default Re: ENVI's codes

On Nov 22, 4:35*pm, Hassan <hkhav...@gmail.com> wrote:
> I used the following code to display the image:
> image=read_tiff(file)
> imagesize=[62,488,290]
> DEVICE, DECOMPOSED = 0
> LOADCT, 38
> WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2]
> TV, Image(0,*,*), 0
>
> but there are two problems: first it's displayed upside-down and
> second the way it shows the image is quite different with other
> softwares like ENVI, it's more like the image is shown in 256-color
> table or something like that.


The upside-down part I can help you with at least. With ENVI the
pixel origin is in the upper left corner of the image. With IDL the
origin is the lower left corner. So add a reverse and you should be
ok:

image = reverse(image,2)

put that aright after you call read_tiff.

As for how its displaying, i'm not sure i understand your description
of the problem, so i'll leave that to smarter folks than me
Reply With Quote
  #8 (permalink)  
Old 11-23-2009, 10:27 AM
Carsten Lechte
Guest
 
Posts: n/a
Default Re: ENVI's codes

Hassan wrote:
> but there are two problems: first it's displayed upside-down and
> second the way it shows the image is quite different with other
> softwares like ENVI, it's more like the image is shown in 256-color
> table or something like that.


The first can be fixed by using the /ORDER keyword to TV.

The second is how TV is supposed to work. Maybe the tvscale procedure
from http://www.dfanning.com/documents/programs.html can help (I do not
use it myself).


chl
Reply With Quote
  #9 (permalink)  
Old 11-23-2009, 12:20 PM
Hassan
Guest
 
Posts: n/a
Default Re: ENVI's codes

On Nov 23, 12:18*am, Jiek <676215...@qq.com> wrote:
> On Nov 23, 5:35*am, Hassan <hkhav...@gmail.com> wrote:
>
> > I used the following code to display the image:
> > image=read_tiff(file)
> > imagesize=[62,488,290]
> > DEVICE, DECOMPOSED = 0
> > LOADCT, 38
> > WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2]
> > TV, Image(0,*,*), 0

>
> > but there are two problems: first it's displayed upside-down and
> > second the way it shows the image is quite different with other
> > softwares like ENVI, it's more like the image is shown in 256-color
> > table or something like that.

>
> I found a function to read ENVI image and it work well.As follows:
> pro read_envi_image, infile, img, xs, ys, type, offset, mapinfo
>
> ;
> ; Copyright (c) 2003,Institute of Photogrammetry and Remote Sensing, ;
> (IPF),
> ; Technical University of Vienna. Unauthorised reproduction
> prohibited.
> ;
> ;+
> ; NAME:
> ; read_envi_file
> ;
> ; PURPOSE:
> ; IDL program, which reads standard ENVI image files (*.img).
> ;
> ;
> ; CATEGORY:
> ; Input_Output
> ;
> ; CALLING SEQUENCE:
> ; read_envi_file, infile, img, xs, ys, type,offset
> ;
> ; INPUTS:
> ; infile - input file name
> ;
> ; OPTIONAL INPUTS:
> ; None
> ;
> ; KEYWORD PARAMETERS:
> ; None
> ;
> ; OUTPUTS:
> ; img - ENVI image file, 2D array
> ; xs - number of samples
> ; ys - number of lines
> ; type - image data type
> ; offset - headeroffset
> ; mapinfo - information on spatial resolution (spacing) and
> coordinates
> ; of upper left corner (ulx, uly)
> ;
> ;
> ; OPTIONAL OUTPUTS:
> ; None
> ;
> ; COMMON BLOCKS:
> ; none
> ;
> ; SIDE EFFECTS:
> ;
> ; RESTRICTIONS:
> ; None
> ;
> ; PROCEDURE:
> ;
> ; EXAMPLE:
> ;
> ; REMARKS
> ; None
> ;
> ; MODIFICATION HISTORY:
> ; Written by: Carsten Pathe, c...@ipf.tuwien.ac.at
> ; Date: 25.08.2003
> ;
> ;-
>
> image = infile
>
> header = strsplit(infile,'.',/extract)
> header = header(n_elements(header)-2)+'.hdr'
>
> openr, unit, header, /get_lun
>
> header_line = ''
>
> while not eof(unit) do begin
>
> readf, unit, header_line
> tmp = strsplit(header_line(0), '=', /extract)
> header_keyword = strsplit(tmp(0), ' ', /extract)
>
> print, header_keyword
>
> if header_keyword(0) eq 'samples' then xs = long(tmp(1))
> if header_keyword(0) eq 'lines' then ys = long(tmp(1))
> if header_keyword(0) eq 'header' then offset = long(tmp(1))
> if header_keyword(0) eq 'data' then type = long(tmp(1))
>
> if header_keyword(0) eq 'map' then begin
>
> mapinfo_tmp=strsplit(tmp(1),'{',/extract)
> mapinfo_tmp=strsplit(mapinfo_tmp(1),',',/extract)
>
> mapinfo={ulx:0.,uly:0.,spacing:0.}
> mapinfo.ulx=mapinfo_tmp(3)
> mapinfo.uly=mapinfo_tmp(4)
> mapinfo.spacing=mapinfo_tmp(5)
>
> endif
>
> endwhile
>
> close,unit & free_lun, unit
> print, xs, ys
>
> if type eq 1 then img=bytarr(xs, ys)
> if type eq 2 then img=intarr(xs, ys)
> if type eq 4 then img=fltarr(xs, ys)
> if type eq 12 then img=uintarr(xs, ys)
>
> openr, unit,image, /get_lun
> point_lun, unit, offset
> readu, unit, img
> close, unit & free_lun, unit
>
> end


I run it but it seems it imports just one band, right? is the output
variable named 'img'?
Reply With Quote
  #10 (permalink)  
Old 11-23-2009, 02:20 PM
jeanh
Guest
 
Posts: n/a
Default Re: ENVI's codes

Hassan wrote:
> I used the following code to read an ENVI file into IDL:
>
> refImage = READ_BINARY(file, DATA_DIMS = imageSize)
>
>[...]anyway, the resulting display
> seems to show a superimposed of the features.


Hi,

this is a typical data type problem.
By default, read_binary reads byte data. If you have floats or else,
this superimposition would occur (though I always witness it the other
way around, when saving a float declared as byte in IDL and opening the
image in Envi). See the DATA_TYPE keywork for read_binary

Jean
Reply With Quote
  #11 (permalink)  
Old 11-23-2009, 02:29 PM
jeanh
Guest
 
Posts: n/a
Default Re: ENVI's codes

Hassan wrote:
> On Nov 23, 12:18 am, Jiek <676215...@qq.com> wrote:
>> On Nov 23, 5:35 am, Hassan <hkhav...@gmail.com> wrote:
>>
>>> I used the following code to display the image:
>>> image=read_tiff(file)
>>> imagesize=[62,488,290]
>>> DEVICE, DECOMPOSED = 0
>>> LOADCT, 38
>>> WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2]
>>> TV, Image(0,*,*), 0
>>> but there are two problems: first it's displayed upside-down and
>>> second the way it shows the image is quite different with other
>>> softwares like ENVI, it's more like the image is shown in 256-color
>>> table or something like that.

>> I found a function to read ENVI image and it work well.As follows:
>> pro read_envi_image, infile, img, xs, ys, type, offset, mapinfo
>>
>> ;
>> ; Copyright (c) 2003,Institute of Photogrammetry and Remote Sensing, ;
>> (IPF),
>> ; Technical University of Vienna. Unauthorised reproduction
>> prohibited.
>> ;
>> ;+
>> ; NAME:
>> ; read_envi_file
>> ;
>> ; PURPOSE:
>> ; IDL program, which reads standard ENVI image files (*.img).
>> ;
>> ;
>> ; CATEGORY:
>> ; Input_Output
>> ;
>> ; CALLING SEQUENCE:
>> ; read_envi_file, infile, img, xs, ys, type,offset
>> ;
>> ; INPUTS:
>> ; infile - input file name
>> ;
>> ; OPTIONAL INPUTS:
>> ; None
>> ;
>> ; KEYWORD PARAMETERS:
>> ; None
>> ;
>> ; OUTPUTS:
>> ; img - ENVI image file, 2D array
>> ; xs - number of samples
>> ; ys - number of lines
>> ; type - image data type
>> ; offset - headeroffset
>> ; mapinfo - information on spatial resolution (spacing) and
>> coordinates
>> ; of upper left corner (ulx, uly)
>> ;
>> ;
>> ; OPTIONAL OUTPUTS:
>> ; None
>> ;
>> ; COMMON BLOCKS:
>> ; none
>> ;
>> ; SIDE EFFECTS:
>> ;
>> ; RESTRICTIONS:
>> ; None
>> ;
>> ; PROCEDURE:
>> ;
>> ; EXAMPLE:
>> ;
>> ; REMARKS
>> ; None
>> ;
>> ; MODIFICATION HISTORY:
>> ; Written by: Carsten Pathe, c...@ipf.tuwien.ac.at
>> ; Date: 25.08.2003
>> ;
>> ;-
>>
>> image = infile
>>
>> header = strsplit(infile,'.',/extract)
>> header = header(n_elements(header)-2)+'.hdr'
>>
>> openr, unit, header, /get_lun
>>
>> header_line = ''
>>
>> while not eof(unit) do begin
>>
>> readf, unit, header_line
>> tmp = strsplit(header_line(0), '=', /extract)
>> header_keyword = strsplit(tmp(0), ' ', /extract)
>>
>> print, header_keyword
>>
>> if header_keyword(0) eq 'samples' then xs = long(tmp(1))
>> if header_keyword(0) eq 'lines' then ys = long(tmp(1))
>> if header_keyword(0) eq 'header' then offset = long(tmp(1))
>> if header_keyword(0) eq 'data' then type = long(tmp(1))
>>
>> if header_keyword(0) eq 'map' then begin
>>
>> mapinfo_tmp=strsplit(tmp(1),'{',/extract)
>> mapinfo_tmp=strsplit(mapinfo_tmp(1),',',/extract)
>>
>> mapinfo={ulx:0.,uly:0.,spacing:0.}
>> mapinfo.ulx=mapinfo_tmp(3)
>> mapinfo.uly=mapinfo_tmp(4)
>> mapinfo.spacing=mapinfo_tmp(5)
>>
>> endif
>>
>> endwhile
>>
>> close,unit & free_lun, unit
>> print, xs, ys
>>
>> if type eq 1 then img=bytarr(xs, ys)
>> if type eq 2 then img=intarr(xs, ys)
>> if type eq 4 then img=fltarr(xs, ys)
>> if type eq 12 then img=uintarr(xs, ys)
>>
>> openr, unit,image, /get_lun
>> point_lun, unit, offset
>> readu, unit, img
>> close, unit & free_lun, unit
>>
>> end

>
> I run it but it seems it imports just one band, right? is the output
> variable named 'img'?



This function is incomplete. You can customize it so it also reads the
number of bands... and the band data.
Also, if you read an Envi file, you may be interested in reading the
lookup table from the header (if any), so that you can display the data
with the exact same color in Envi and in IDL.

By the way, you say you want to do this in IDL, but you didn't specify
if you have to get rid of using Envi or not. If not, you can use the
following (note: again, the info read in the header is incomplete and
suits my need... feel free to read more info, such as the number of
bands AND the information on the band interleave..


;Open the file in envi
ENVI_OPEN_FILE, fileToOpen, /NO_REALIZE , R_FID=FID

;If it is a valid file, read the header
if (fid[0] eq -1) then return, -1
envi_file_query, fid, ns=dimX, nl=dimY, nb=nbBands, DATA_TYPE=dataType,$
OFFSET = HeaderOffSet, LOOKUP= lookup, class_names = classNames,$
num_classes = numClasses
map_Info = ENVI_GET_MAP_INFO(FID=FID)

;Pack the header info in a structure (optional)
headerInfo = {ns:dimX, nl:dimY, lookup:lookup, map_info:map_Info,$
class_names:classNames, num_classes:numClasses}

;Read the data in IDL
data = read_binary(fileToOpen,data_Start = HeaderOffSet,$
data_Type=dataType, data_Dims=[dimX,dimY],ENDIAN = "native")


Jean
Reply With Quote
  #12 (permalink)  
Old 11-25-2009, 10:40 AM
Hassan
Guest
 
Posts: n/a
Default Re: ENVI's codes

On Nov 23, 3:29*pm, jeanh
<jghasb...@DELETETHIS.environmentalmodelers.ANDTHI S.com> wrote:
> Hassan wrote:
> > On Nov 23, 12:18 am, Jiek <676215...@qq.com> wrote:
> >> On Nov 23, 5:35 am, Hassan <hkhav...@gmail.com> wrote:

>
> >>> I used the following code to display the image:
> >>> image=read_tiff(file)
> >>> imagesize=[62,488,290]
> >>> DEVICE, DECOMPOSED = 0
> >>> LOADCT, 38
> >>> WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2]
> >>> TV, Image(0,*,*), 0
> >>> but there are two problems: first it's displayed upside-down and
> >>> second the way it shows the image is quite different with other
> >>> softwares like ENVI, it's more like the image is shown in 256-color
> >>> table or something like that.
> >> I found a function to read ENVI image and it work well.As follows:
> >> pro read_envi_image, infile, img, xs, ys, type, offset, mapinfo

>
> >> ;
> >> ; Copyright (c) 2003,Institute of Photogrammetry and Remote Sensing, ;
> >> (IPF),
> >> ; Technical University of Vienna. Unauthorised reproduction
> >> prohibited.
> >> ;
> >> ;+
> >> ; NAME:
> >> ; read_envi_file
> >> ;
> >> ; PURPOSE:
> >> ; IDL program, which reads standard ENVI image files (*.img).
> >> ;
> >> ;
> >> ; CATEGORY:
> >> ; Input_Output
> >> ;
> >> ; CALLING SEQUENCE:
> >> ; read_envi_file, infile, img, xs, ys, type,offset
> >> ;
> >> ; INPUTS:
> >> ; infile - input file name
> >> ;
> >> ; OPTIONAL INPUTS:
> >> ; None
> >> ;
> >> ; KEYWORD PARAMETERS:
> >> ; None
> >> ;
> >> ; OUTPUTS:
> >> ; img - ENVI image file, 2D array
> >> ; xs - number of samples
> >> ; ys - number of lines
> >> ; type - image data type
> >> ; offset - headeroffset
> >> ; mapinfo - information on spatial resolution (spacing) and
> >> coordinates
> >> ; of upper left corner (ulx, uly)
> >> ;
> >> ;
> >> ; OPTIONAL OUTPUTS:
> >> ; None
> >> ;
> >> ; COMMON BLOCKS:
> >> ; none
> >> ;
> >> ; SIDE EFFECTS:
> >> ;
> >> ; RESTRICTIONS:
> >> ; None
> >> ;
> >> ; PROCEDURE:
> >> ;
> >> ; EXAMPLE:
> >> ;
> >> ; REMARKS
> >> ; None
> >> ;
> >> ; MODIFICATION HISTORY:
> >> ; Written by: Carsten Pathe, c...@ipf.tuwien.ac.at
> >> ; Date: 25.08.2003
> >> ;
> >> ;-

>
> >> image = infile

>
> >> header = strsplit(infile,'.',/extract)
> >> header = header(n_elements(header)-2)+'.hdr'

>
> >> openr, unit, header, /get_lun

>
> >> header_line = ''

>
> >> while not eof(unit) do begin

>
> >> readf, unit, header_line
> >> tmp = strsplit(header_line(0), '=', /extract)
> >> header_keyword = strsplit(tmp(0), ' ', /extract)

>
> >> print, header_keyword

>
> >> if header_keyword(0) eq 'samples' then xs = long(tmp(1))
> >> if header_keyword(0) eq 'lines' then ys = long(tmp(1))
> >> if header_keyword(0) eq 'header' then offset = long(tmp(1))
> >> if header_keyword(0) eq 'data' then type = long(tmp(1))

>
> >> if header_keyword(0) eq 'map' then begin

>
> >> mapinfo_tmp=strsplit(tmp(1),'{',/extract)
> >> mapinfo_tmp=strsplit(mapinfo_tmp(1),',',/extract)

>
> >> mapinfo={ulx:0.,uly:0.,spacing:0.}
> >> mapinfo.ulx=mapinfo_tmp(3)
> >> mapinfo.uly=mapinfo_tmp(4)
> >> mapinfo.spacing=mapinfo_tmp(5)

>
> >> endif

>
> >> endwhile

>
> >> close,unit & free_lun, unit
> >> print, xs, ys

>
> >> if type eq 1 then img=bytarr(xs, ys)
> >> if type eq 2 then img=intarr(xs, ys)
> >> if type eq 4 then img=fltarr(xs, ys)
> >> if type eq 12 then img=uintarr(xs, ys)

>
> >> openr, unit,image, /get_lun
> >> point_lun, unit, offset
> >> readu, unit, img
> >> close, unit & free_lun, unit

>
> >> end

>
> > I run it but it seems it imports just one band, right? is the output
> > variable named 'img'?

>
> This function is incomplete. You can customize it so it also reads the
> number of bands... and the band data.
> Also, if you read an Envi file, you may be interested in reading the
> lookup table from the header (if any), so that you can display the data
> with the exact same color in Envi and in IDL.
>
> By the way, you say you want to do this in IDL, but you didn't specify
> if you have to get rid of using Envi or not. If not, you can use the
> following (note: again, the info read in the header is incomplete and
> suits my need... feel free to read more info, such as the number of
> bands AND the information on the band interleave..
>
> ;Open the file in envi
> ENVI_OPEN_FILE, fileToOpen, /NO_REALIZE , R_FID=FID
>
> ;If it is a valid file, read the header
> if (fid[0] eq -1) then return, -1
> envi_file_query, fid, ns=dimX, nl=dimY, nb=nbBands, DATA_TYPE=dataType,$
> * * OFFSET = HeaderOffSet, LOOKUP= lookup, class_names = classNames,$
> * * num_classes = numClasses
> map_Info = ENVI_GET_MAP_INFO(FID=FID)
>
> ;Pack the header info in a structure (optional)
> headerInfo = {ns:dimX, nl:dimY, lookup:lookup, map_info:map_Info,$
> * * * * class_names:classNames, num_classes:numClasses}
>
> ;Read the data in IDL
> data = read_binary(fileToOpen,data_Start = HeaderOffSet,$
> * * * * data_Type=dataType, data_Dims=[dimX,dimY],ENDIAN = "native")
>
> Jean


thanks for that. but i still cant display the image as envi does,
there's no look up table in header file but i should be able to make
one.
Reply With Quote
  #13 (permalink)  
Old 11-25-2009, 10:55 AM
Hassan
Guest
 
Posts: n/a
Default Re: ENVI's codes

On Nov 23, 12:18*am, Jiek <676215...@qq.com> wrote:
> On Nov 23, 5:35*am, Hassan <hkhav...@gmail.com> wrote:
>
> > I used the following code to display the image:
> > image=read_tiff(file)
> > imagesize=[62,488,290]
> > DEVICE, DECOMPOSED = 0
> > LOADCT, 38
> > WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2]
> > TV, Image(0,*,*), 0

>
> > but there are two problems: first it's displayed upside-down and
> > second the way it shows the image is quite different with other
> > softwares like ENVI, it's more like the image is shown in 256-color
> > table or something like that.

>
> I found a function to read ENVI image and it work well.As follows:
> pro read_envi_image, infile, img, xs, ys, type, offset, mapinfo
>
> ;
> ; Copyright (c) 2003,Institute of Photogrammetry and Remote Sensing, ;
> (IPF),
> ; Technical University of Vienna. Unauthorised reproduction
> prohibited.
> ;
> ;+
> ; NAME:
> ; read_envi_file
> ;
> ; PURPOSE:
> ; IDL program, which reads standard ENVI image files (*.img).
> ;
> ;
> ; CATEGORY:
> ; Input_Output
> ;
> ; CALLING SEQUENCE:
> ; read_envi_file, infile, img, xs, ys, type,offset
> ;
> ; INPUTS:
> ; infile - input file name
> ;
> ; OPTIONAL INPUTS:
> ; None
> ;
> ; KEYWORD PARAMETERS:
> ; None
> ;
> ; OUTPUTS:
> ; img - ENVI image file, 2D array
> ; xs - number of samples
> ; ys - number of lines
> ; type - image data type
> ; offset - headeroffset
> ; mapinfo - information on spatial resolution (spacing) and
> coordinates
> ; of upper left corner (ulx, uly)
> ;
> ;
> ; OPTIONAL OUTPUTS:
> ; None
> ;
> ; COMMON BLOCKS:
> ; none
> ;
> ; SIDE EFFECTS:
> ;
> ; RESTRICTIONS:
> ; None
> ;
> ; PROCEDURE:
> ;
> ; EXAMPLE:
> ;
> ; REMARKS
> ; None
> ;
> ; MODIFICATION HISTORY:
> ; Written by: Carsten Pathe, c...@ipf.tuwien.ac.at
> ; Date: 25.08.2003
> ;
> ;-
>
> image = infile
>
> header = strsplit(infile,'.',/extract)
> header = header(n_elements(header)-2)+'.hdr'
>
> openr, unit, header, /get_lun
>
> header_line = ''
>
> while not eof(unit) do begin
>
> readf, unit, header_line
> tmp = strsplit(header_line(0), '=', /extract)
> header_keyword = strsplit(tmp(0), ' ', /extract)
>
> print, header_keyword
>
> if header_keyword(0) eq 'samples' then xs = long(tmp(1))
> if header_keyword(0) eq 'lines' then ys = long(tmp(1))
> if header_keyword(0) eq 'header' then offset = long(tmp(1))
> if header_keyword(0) eq 'data' then type = long(tmp(1))
>
> if header_keyword(0) eq 'map' then begin
>
> mapinfo_tmp=strsplit(tmp(1),'{',/extract)
> mapinfo_tmp=strsplit(mapinfo_tmp(1),',',/extract)
>
> mapinfo={ulx:0.,uly:0.,spacing:0.}
> mapinfo.ulx=mapinfo_tmp(3)
> mapinfo.uly=mapinfo_tmp(4)
> mapinfo.spacing=mapinfo_tmp(5)
>
> endif
>
> endwhile
>
> close,unit & free_lun, unit
> print, xs, ys
>
> if type eq 1 then img=bytarr(xs, ys)
> if type eq 2 then img=intarr(xs, ys)
> if type eq 4 then img=fltarr(xs, ys)
> if type eq 12 then img=uintarr(xs, ys)
>
> openr, unit,image, /get_lun
> point_lun, unit, offset
> readu, unit, img
> close, unit & free_lun, unit
>
> end


it's really useful code, thanks for that. although after running the
code, it doesnt ask me for input file and it should be defined into
the code but it should be straightforward to do that.
Reply With Quote
  #14 (permalink)  
Old 11-25-2009, 11:02 AM
Hassan
Guest
 
Posts: n/a
Default Re: ENVI's codes

On Nov 23, 12:27*am, "Jeff N." <jeffnettles4...@gmail.com> wrote:
> On Nov 22, 4:35*pm, Hassan <hkhav...@gmail.com> wrote:
>
> > I used the following code to display the image:
> > image=read_tiff(file)
> > imagesize=[62,488,290]
> > DEVICE, DECOMPOSED = 0
> > LOADCT, 38
> > WINDOW, 0, XSIZE = imageSize[1], YSIZE = imageSize[2]
> > TV, Image(0,*,*), 0

>
> > but there are two problems: first it's displayed upside-down and
> > second the way it shows the image is quite different with other
> > softwares like ENVI, it's more like the image is shown in 256-color
> > table or something like that.

>
> The upside-down part I can help you with at least. *With ENVI the
> pixel origin is in the upper left corner of the image. *With IDL the
> origin is the lower left corner. *So add a reverse and you should be
> ok:
>
> image = reverse(image,2)
>
> put that aright after you call read_tiff.
>
> As for how its displaying, i'm not sure i understand your description
> of the problem, so i'll leave that to smarter folks than me


i used reverse but it didnt work the upside-down problem.
Reply With Quote
  #15 (permalink)  
Old 11-25-2009, 11:04 AM
Hassan
Guest
 
Posts: n/a
Default Re: ENVI's codes

On Nov 23, 11:27*am, Carsten Lechte <c...@toppoint.de> wrote:
> Hassan wrote:
> > but there are two problems: first it's displayed upside-down and
> > second the way it shows the image is quite different with other
> > softwares like ENVI, it's more like the image is shown in 256-color
> > table or something like that.

>
> The first can be fixed by using the /ORDER keyword to TV.
>
> The second is how TV is supposed to work. Maybe the tvscale procedure
> fromhttp://www.dfanning.com/documents/programs.htmlcan help (I do not
> use it myself).
>
> chl


order works fine. thanks for that.
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: creating an array of matching ICD9 codes Kevin Viel Newsgroup comp.soft-sys.sas 0 02-27-2009 02:10 PM
Re: creating an array of matching ICD9 codes John Burton Newsgroup comp.soft-sys.sas 0 02-25-2009 12:22 AM
Re: Is there a sas code that can clean up ICD-9 codes? Sigurd Hermansen Newsgroup comp.soft-sys.sas 0 02-24-2005 04:00 PM
Re: Is there a sas code that can clean up ICD-9 codes? Duck-Hye Yang Newsgroup comp.soft-sys.sas 1 02-22-2005 09:23 PM
Re: Is there a sas code that can clean up ICD-9 codes? Jonathan Kerman Newsgroup comp.soft-sys.sas 1 02-22-2005 08:37 PM



All times are GMT. The time now is 06:33 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.