Re: save image from ENVI to TIFF file [message #52189] |
Mon, 15 January 2007 15:07 |
Jeff N.
Messages: 120 Registered: April 2005
|
Senior Member |
|
|
You don't need the loop if you're extracting consecutive bands, and you
don't really even need the call to MAKE_ARRAY(). This can often be
done in one step:
WRITE_TIFF, 'output_filename.tif', ENVI_GET_DATA(...)
The trick is to give ENVI_GET_DATA() and WRITE_TIFF() the right
keywords, and the value of those keywords depends on the size of the
input image and the size of the subset of that image you're trying to
extract. I typically use ENVI_FILE_QUERY to get the number of samples,
lines, and bands of my input image and put them in variables like ns,
nl, and nb, respectively. You can then build a DIMS array for spatial
dimensions and a POS array for band positions. So, if you wanted to
just write the first three bands of an image out to a tif file without
spatial subsetting, try something like this:
dims = [-1,0, ns - 1, 0, nl - 1]
pos = [0,1,2]
WRITE_TIFF, 'output_filename.tif', ENVI_GET_DATA(FID=fid, DIMS=dims,
POS=pos)
But, of course, you will probably need to set the TRUE keyword to
WRITE_TIFF() based on the interleave of the input data (or depending on
how you called ENVI_GET_DATA). The basic idea is that you've got to be
able to completely and correctly describe the subset of the input image
cube that you want to write out. If you do this, you shouldn't have
much trouble with either WRITE_TIFF() or with
ENVI_OUTPUT_TO_EXTERNAL_FORMAT. I'd say 95% of the time i have trouble
with this sort of task it's b/c a keyword i thought i had right is
actually wrong, so just keep working on those keywords and you'll get
it. One piece of advice: ALWAYS have both the ENVI and IDL help
running while you write code :)
Hope that helps,
Jeff
|
|
|
Re: save image from ENVI to TIFF file [message #52192 is a reply to message #52189] |
Mon, 15 January 2007 09:29  |
skymaxwell@gmail.com
Messages: 127 Registered: January 2007
|
Senior Member |
|
|
i do this
> ns = pan_dims[2]-pan_dims[1]+1
> nl = pan_dims[4]-pan_dims[3]+1
> image=MAKE_ARRAY(number_bands,ns,nl,/BYTE)
>
>
> Cheers
>
> Mort
now i get ENVI error dialog
ENVI retrieve Data: An error has occuring during processing
Error "READ_TIFF:Invalid SUB_RECT. Portions lie outside of
the image". The result may be invalid
i don't use READ_TIFF procedure in my program ? why i catch this error ?
|
|
|
Re: save image from ENVI to TIFF file [message #52194 is a reply to message #52192] |
Mon, 15 January 2007 06:15  |
Mort Canty
Messages: 134 Registered: March 2003
|
Senior Member |
|
|
skymaxwell@gmail.com schrieb:
> here is my last variant for EXTERNAL_FORMAT and new variant for
> WRITE_TIFF as recommended
>
> ;ENVI_OUTPUT_TO_EXTERNAL_FORMAT,OUT_NAME=full_file_name+'_MY _.TIFF',DIMS=pan_dims,$
> ; POS=pos_mul,/TIFF,FID=pansharp_fid
>
> image=MAKE_ARRAY(number_bands,pan_dims[2],pan_dims[4],/BYTE)
>
> FOR I=0,number_bands-1 DO BEGIN
> image[I,*,*]=ENVI_GET_DATA(DIMS=pan_dims,POS=I,FID=fid_Src_m ul)
> ;image[I,*,*]=ENVI_GET_IMAGE(BAND_POS=I,DIMS=pan_dims)
> ENDFOR
> WRITE_TIFF,full_file_name+'_MY_.TIFF',image
>
Your MAKE_ARRAY() is incorrect. Try
ns = pan_dims[2]-pan_dims[1]+1
nl = pan_dims[4]-pan_dims[3]+1
image=MAKE_ARRAY(number_bands,ns,nl,/BYTE)
Cheers
Mort
|
|
|
Re: save image from ENVI to TIFF file [message #52195 is a reply to message #52194] |
Mon, 15 January 2007 02:39  |
skymaxwell@gmail.com
Messages: 127 Registered: January 2007
|
Senior Member |
|
|
here is my last variant for EXTERNAL_FORMAT and new variant for
WRITE_TIFF as recommended
;ENVI_OUTPUT_TO_EXTERNAL_FORMAT,OUT_NAME=full_file_name+'_MY _.TIFF',DIMS=pan_dims,$
; POS=pos_mul,/TIFF,FID=pansharp_fid
image=MAKE_ARRAY(number_bands,pan_dims[2],pan_dims[4],/BYTE)
FOR I=0,number_bands-1 DO BEGIN
image[I,*,*]=ENVI_GET_DATA(DIMS=pan_dims,POS=I,FID=fid_Src_m ul)
;image[I,*,*]=ENVI_GET_IMAGE(BAND_POS=I,DIMS=pan_dims)
ENDFOR
WRITE_TIFF,full_file_name+'_MY_.TIFF',image
|
|
|
Re: save image from ENVI to TIFF file [message #52199 is a reply to message #52195] |
Sun, 14 January 2007 14:32  |
Jeff N.
Messages: 120 Registered: April 2005
|
Senior Member |
|
|
There are lots of ways to do this. ENVI_OUTPUT_TO_EXTERNAL_FORMAT is
one, but another is just to use good old WRITE_TIFF(). Why don't you
show us your code....you are more than likely setting some keywords
wrong.
Jeff
skymaxwell@gmail.com wrote:
> Hello
>
> how save image from ENVI to TIFF file?
>
> i try use ENVI_OUTPUT_TO_EXTERNAL_FORMAT and/or CF_DOIT procedures
> nothing happened or only one band was saved. How save multiband file to
> TIFF ?
>
> Thanks
|
|
|