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

Home » Public Forums » archive » Help with code for hyperspectral image analysis
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Help with code for hyperspectral image analysis [message #80511 is a reply to message #80374] Thu, 21 June 2012 13:37 Go to previous messageGo to previous message
Kel is currently offline  Kel
Messages: 7
Registered: June 2012
Junior Member
I'm testing code on a tiny file now, and it's getting really close! Still not quite what I need though.
I've simplified the operations that I want to do on the image data just to get the basic code set up, because something is going weird in writing the output file. Masking high-magnitude pixels was the original goal, now I'm just trying to increase the magnitude of each band by 2.

Goal: open an ENVI image file, use a for-loop to do a simple math operation (add 2), create a new ENVI output image that looks just like the old one but with a slightly higher magnitude across all bands.

Result: The output image file displays the expected samples, lines, and bands, but the band values have no relationship to the band values of the input file, as far as I can tell. How did they get so crazy?

Thanks again for the help, I would never have managed this on my own!

;select your image file
image=filepath('tinyfile', root_dir='d:', subdirectory=['idl'])

output=filepath('tiny2', root_dir='d:', subdirectory=['idl'])

;check to see if valid for ENVI
envi_open_file, image, r_fid=fid

;learn about the image
ENVI_FILE_QUERY, fid, ns=ns, nl=nl, nb=nb, data_type=data_type, interleave=interleave, map_info=map_info
help, data_type

;build array based on data type
data_holder=intarr(ns, nb, nl)
help, data_holder

;open a new file for reading as IDL file unit number 1
openr, 1, image

;write the data in my image file to the file 'data_array'
readu, 1, data_holder
close, 1

dims = [-1, 0, ns-1, 0, nl-1]

OpenW, lun, output, /Get_Lun
for i=0,nb-1 do begin
data = ENVI_GET_DATA(fid=fid, dims=dims, pos=i)
newdata = data+2
writeu, lun, newdata

endfor

; close binary file
close, lun
free_lun, lun

; write out an envi header file
envi_setup_head, Data_Type=data_type, /Open, R_FID=masked_fid, /WRITE, FNAME=output, Interleave=1, ns=ns, nl=nl, nb=nb







On Wednesday, June 20, 2012 4:24:54 PM UTC-4, Kel wrote:
> Update: Still running out of memory. I've already changed the values in the idlde.ini file, as recommended in other posts, but now I'm stuck. Google is suggesting that I increase the virtual memory of my pc, so I will give that a try.
>
> On Wednesday, June 20, 2012 3:59:36 PM UTC-4, Kel wrote:
>> Thanks you both so much! I had just gotten an out-of-memory error on Klemen's code, which seemed to be going ok up until that point, so I will try this modification now and hope it helps.
>>
>> On Wednesday, June 20, 2012 3:55:08 PM UTC-4, Brian J. Daniel wrote:
>>> See my adjustments to Klemen's code below. This way you don't have to load the entire image, masked or otherwise, into memory. Also, untested.
>>>
>>> pro envi_masking_image
>>>
>>> ;select your image file
>>>
>>> ;Get your file
>>> image=dialog_pickfile()
>>>
>>> ; Pick an output filename
>>> output = dialog_pickfile()
>>>
>>> ;check to see if valid for ENVI
>>> envi_open_file, image, r_fid=fid
>>> IF fid[0] EQ -1 THEN Message,'Invalid file name: '+image
>>>
>>> ;learn about the image
>>> ENVI_FILE_QUERY, fid, ns=ns, nl=nl, nb=nb, data_type=data_type,Interleave=interleave
>>> help, data_type
>>>
>>> ;build array based on data type
>>> ;data_holder=Make_Array(ns, nb, nl, Type=data_type) ; memory intensive
>>>
>>> ;make a mask
>>> f = ENVI_GET_DATA(fid=fid, dims=dims, pos=140)
>>> indx = where(f LT 40, count)
>>> f[indx] = 0 ; now f is your mask
>>>
>>> ;apply the mask to all bands and save
>>> OpenW, lun, output, /Get_Lun
>>> if count gt 0 then begin
>>> for i=0,nl-1 do begin
>>> data = ENVI_GET_DATA(fid=fid, dims=dims, pos=i)
>>> writeu,lun,data*f
>>>
>>> endfor
>>> endif
>>>
>>> ; close binary file
>>> close,lun
>>> free_lun, lun
>>>
>>> ; write out an envi header file
>>> envi_setup_head, Data_Type=data_type, /Open, R_FID=masked_fid, $
>>> /WRITE, FNAME=output, Interleave=2 ; BIP
>>>
>>> end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: read irregular data
Next Topic: sun symbol

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

Current Time: Fri Oct 10 10:09:39 PDT 2025

Total time taken to generate the page: 0.71514 seconds