Re: divise image envi-idl [message #70946] |
Thu, 20 May 2010 14:03 |
tonino
Messages: 4 Registered: May 2010
|
Junior Member |
|
|
Sorry for the last message. I found the solution. The problem was
still the outname which must be written this way :
outname='C:\Documents and Settings\Administrateur\Mes documents
\'+strtrim(i/(NSimage/5),2)+strtrim(j/(NLimage/2),2)+'.img'
thank you very much
tonino
|
|
|
Re: divise image envi-idl [message #70947 is a reply to message #70946] |
Thu, 20 May 2010 13:22  |
tonino
Messages: 4 Registered: May 2010
|
Junior Member |
|
|
Thank you all for your advices...
Now, my program is running. I can even write into my header (so nice).
The last problem is that my images ar not recognized when when I try
to open them with ENVI :
pro tuilage
;ENVI, /RESTORE_BASE_SAVE_FILES
ENVI_BATCH_INIT
image = 'C:\Documents and Settings\Administrateur\Mes documents
\cooccurrence+1+2'
envi_open_file, image, r_fid=fidimage, /NO_REALIZE
if (fidimage eq -1) then begin
print, 'error nestor'
endif
envi_file_query, fidimage, dims = dimimage, NB=NBimage, NL=NLimage,
NS=NSimage, Bnames=Bnamesimage, data_type = data_type
pos = lindgen(NBimage)
openr, lun, image, /get_lun
espace = fltarr(NSimage, NLimage, NBimage)
READU,lun, espace
result = fltarr(NSimage/5, NLimage/2, NBimage)
for i = 0, (NSimage-NSimage/5), NSimage/5 do begin
for j = 0, (NLimage-NLimage/2), NLimage/2 do begin
result = espace[i:i+((NSimage/5)-1),j:j+((NLimage/2)-1),
0:NBimage-1]
mc = [0, 0, 724295*i*(NSimage/5)*2.5, 1635835.0*j*(NLimage/
2)*2.5]
ps=[2.5,2.5]
map_info=envi_map_info_create(/UTM, datum=datum, zone=20, ps=ps,
mc=mc)
outname='C:\Documents and Settings\Administrateur\Mes documents
\'+strtrim(i/(NSimage/5))+strtrim(j/(NLimage/2))+'.img'
envi_write_envi_file, result, data_type=4, nb=NBimage,
nl=NLimage/2, $
ns=NSimage/5, BNAMES=BNamesimages, out_name=outname,
byte_order=0, map_info=map_info
; envi_setup_head, Bnames=Bnamesimage, data_type=4,
fname=strcompress(out_name+'.hdr', /REMOVE_ALL), $
; NS=NSimage/5, NL=NLimage/2, NB=NBimage, $
openw, unit, outname, /Get_lun
writeu, unit, result
free_lun, lun
endfor
endfor
end
|
|
|
Re: divise image envi-idl [message #70958 is a reply to message #70947] |
Wed, 19 May 2010 10:33  |
jeanh
Messages: 79 Registered: November 2009
|
Member |
|
|
outname is still wrong (you DO want to keep some space there... read my
previous post)
Jean
On 19/05/2010 10:17 AM, Antoine Cheula wrote:
> "Jeff N.
>
> "You need to read the image data into memory if you want to subscript
> it this way."
>
> That was the problem. I still have a problem to save my divide images
> with the function envi_write_envi_file...
>
> Now, my program look like this :
>
> pro tuilage
>
> ENVI, /RESTORE_BASE_SAVE_FILES
> ENVI_BATCH_INIT
>
> image = 'C:\Documents and Settings\Administrateur\Mes documents
> \cooccurrence+1+2'
> envi_open_file, image, r_fid=fidimage, /NO_REALIZE
>
> if (fidimage eq -1) then begin
> print, 'error nestor'
> endif
>
> envi_file_query, fidimage, dims = dimimage, NB=NBimage, NL=NLimage,
> NS=NSimage, Bnames=Bnamesimage, data_type = data_type
> pos = lindgen(NBimage)
>
> openr, lun, image, /get_lun
> espace = fltarr(NSimage, NLimage, NBimage)
>
> READU,lun, espace
>
> result = fltarr(NSimage/5, NLimage/2, NBimage)
>
> for i = 0, (NSimage-NSimage/5), NSimage/5 do begin
> for j = 0, (NLimage-NLimage/2), NLimage/2 do begin
>
> result = espace[i:i+((NSimage/5)-1),j:j+((NLimage/2)-1),
> 0:NBimage-1]
>
>
> envi_write_envi_file, result, data_type=4, nb=NBimage,
> nl=NLimage/2, $
> ns=NSimage/5, BNAMES=BNamesimages, $
> outname = STRCOMPRESS('C:\Documents and Settings\Administrateur
> \Mes documents\'+string(i/(NSimage/5))+string(j/(NLimage/2)),/
> REMOVE_ALL)
>
> endfor
> endfor
>
> end
>
|
|
|
Re: divise image envi-idl [message #70959 is a reply to message #70958] |
Wed, 19 May 2010 07:17  |
Antoine Cheula
Messages: 1 Registered: May 2010
|
Junior Member |
|
|
"Jeff N.
"You need to read the image data into memory if you want to subscript
it this way."
That was the problem. I still have a problem to save my divide images
with the function envi_write_envi_file...
Now, my program look like this :
pro tuilage
ENVI, /RESTORE_BASE_SAVE_FILES
ENVI_BATCH_INIT
image = 'C:\Documents and Settings\Administrateur\Mes documents
\cooccurrence+1+2'
envi_open_file, image, r_fid=fidimage, /NO_REALIZE
if (fidimage eq -1) then begin
print, 'error nestor'
endif
envi_file_query, fidimage, dims = dimimage, NB=NBimage, NL=NLimage,
NS=NSimage, Bnames=Bnamesimage, data_type = data_type
pos = lindgen(NBimage)
openr, lun, image, /get_lun
espace = fltarr(NSimage, NLimage, NBimage)
READU,lun, espace
result = fltarr(NSimage/5, NLimage/2, NBimage)
for i = 0, (NSimage-NSimage/5), NSimage/5 do begin
for j = 0, (NLimage-NLimage/2), NLimage/2 do begin
result = espace[i:i+((NSimage/5)-1),j:j+((NLimage/2)-1),
0:NBimage-1]
envi_write_envi_file, result, data_type=4, nb=NBimage,
nl=NLimage/2, $
ns=NSimage/5, BNAMES=BNamesimages, $
outname = STRCOMPRESS('C:\Documents and Settings\Administrateur
\Mes documents\'+string(i/(NSimage/5))+string(j/(NLimage/2)),/
REMOVE_ALL)
endfor
endfor
end
|
|
|
Re: divise image envi-idl [message #70966 is a reply to message #70959] |
Tue, 18 May 2010 12:22  |
jeffnettles4870
Messages: 111 Registered: October 2006
|
Senior Member |
|
|
On May 18, 3:03 pm, jeanh
<jghasb...@DELETETHIS.environmentalmodelers.ANDTHIS.com> wrote:
> On 18/05/2010 1:50 PM, tonino wrote:
>
>> Thank you very much Jean,
>
>> I'm sure those advices will be useful for the next step. For now, the
>> problem concerns the line :
>
>> result = image[i:i+((NSimage/5)-1),j:j+((NLimage/2)-1),0:NBimage-1]
>
>> the error message is :
>
>> Subscript range values of the form low:high must be>= 0,< size, with
>> low<= high: IMAGE.
>> % Execution halted at: TUILAGE 18 C:\Documents and Settings
>> \Administrateur\Mes documents\tuilage.pro
>
> try to print these values... It it probably happening for your last i
> and/or j in the loop. Are you sure than NS is a multiple of 5 and NL of
> 2? if not, you can prepare your index before doing the subscript:
> subNS = (i+((NSimage/5)-1)) < (NSimage-1)
> subNL = (j+((NLimage/2)-1)) < (NLimage-1)
> result = image[i:subNS,j:subNL,0:NBimage-1]
>
> be sure, when you save the result with envi_write_envi_file, to compute
> the proper ns and nl!
>
> Jean
>
>
>
>> and it still comes if I change the data type or if I transform the
>> variable 'result' into a float array...
>
>> I think I don't write the terms of the loop properly
>
>> ... if you have an idea.
>
>> thanks again for your answer
>> nestonino
>
>
Also, the variable named 'image' is not actually holding image data,
it's holding a string that's the path to the file. You need to read
the image data into memory if you want to subscript it this way. You
might eventually think about better ways to do what you want than a
double for-loop like you're doing, but for now, your first problem is
to get the data into memory.
|
|
|
Re: divise image envi-idl [message #70967 is a reply to message #70966] |
Tue, 18 May 2010 12:03  |
jeanh
Messages: 79 Registered: November 2009
|
Member |
|
|
On 18/05/2010 1:50 PM, tonino wrote:
> Thank you very much Jean,
>
> I'm sure those advices will be useful for the next step. For now, the
> problem concerns the line :
>
> result = image[i:i+((NSimage/5)-1),j:j+((NLimage/2)-1),0:NBimage-1]
>
> the error message is :
>
> Subscript range values of the form low:high must be>= 0,< size, with
> low<= high: IMAGE.
> % Execution halted at: TUILAGE 18 C:\Documents and Settings
> \Administrateur\Mes documents\tuilage.pro
try to print these values... It it probably happening for your last i
and/or j in the loop. Are you sure than NS is a multiple of 5 and NL of
2? if not, you can prepare your index before doing the subscript:
subNS = (i+((NSimage/5)-1)) < (NSimage-1)
subNL = (j+((NLimage/2)-1)) < (NLimage-1)
result = image[i:subNS,j:subNL,0:NBimage-1]
be sure, when you save the result with envi_write_envi_file, to compute
the proper ns and nl!
Jean
>
> and it still comes if I change the data type or if I transform the
> variable 'result' into a float array...
>
> I think I don't write the terms of the loop properly
>
> ... if you have an idea.
>
> thanks again for your answer
> nestonino
|
|
|
Re: divise image envi-idl [message #70969 is a reply to message #70967] |
Tue, 18 May 2010 10:50  |
tonino
Messages: 4 Registered: May 2010
|
Junior Member |
|
|
Thank you very much Jean,
I'm sure those advices will be useful for the next step. For now, the
problem concerns the line :
result = image[i:i+((NSimage/5)-1),j:j+((NLimage/2)-1),0:NBimage-1]
the error message is :
Subscript range values of the form low:high must be >= 0, < size, with
low <= high: IMAGE.
% Execution halted at: TUILAGE 18 C:\Documents and Settings
\Administrateur\Mes documents\tuilage.pro
and it still comes if I change the data type or if I transform the
variable 'result' into a float array...
I think I don't write the terms of the loop properly
... if you have an idea.
thanks again for your answer
nestonino
|
|
|
Re: divise image envi-idl [message #70970 is a reply to message #70969] |
Tue, 18 May 2010 09:15  |
jeanh
Messages: 79 Registered: November 2009
|
Member |
|
|
Hi tonino_nestor
> I try to write a batch to divise my image but apparently, the values
> of the loop are wrong... could someone explain me what is wrong ?
what error do you get?
> envi_open_file, image, r_fid=fidimage, /NO_REALIZE
>
> if (fidimage eq -1) then begin
> print, 'error nestor'
> endif
at times, the r_fid can be an array... it works better to test if
(fidimage[0] eq -1)
> result = dblarr(NSimage/5, NLimage/2, NBimage)
result is of type double
> for i = 0, (NSimage-NSimage/5), NSimage/5 do begin
> for j = 0, (NLimage-NLimage/2), NLimage/2 do begin
>
> result = image[i:i+((NSimage/5)-1),j:j+((NLimage/2)-1),
> 0:NBimage-1]
result is of the type of image (float? double? int?)
> envi_write_envi_file, result, data_type=4
> outname = STRCOMPRESS('C:\Documents and Settings\Administrateur
> \Mesdocume\'+string(i/(NSimage/5))+string(j/(NLimage/2)),/RE MOVE_ALL)
> openw, lun, outname, /Get_lun
> close, lun
> free_lun, lun
here is your problem...
1) the output is of type float. So, if image is a double, your problem
is here!, change the data_type.
2) you need to specify more argument than that to envi_write_envi_file,
including the outname (if you don't want to have the output only in
memory), ns, nl, nb... see the help file.
3) you open and close the file... this is useless.
4) don't use STRCOMPRESS this way. The output would be, for the
begining: C:\DocumentsandSettings\ which is, I believe, not the
directory you are looking for. Instead, use strtrim ==>
+string(i/(NSimage/5)) becomes +strtrim(i/(NSimage/5),2)
Jean
> endfor
> endfor
>
> end
|
|
|