<div dir="ltr">Dear all:<div><br><div>The problem I was facing has been solved. I detected that the problem was with the band number '0'. Solution is: the band number starts from '1'.</div><div><br></div><div>
But, the gdal documentation says that the default band number is '0'. </div><div><a href="http://www.gdal.org/gdal_calc.html">http://www.gdal.org/gdal_calc.html</a> </div><div><br></div><div>The documentation should be corrected, I think.</div>
<div><br></div><div>The default band number is '1'.</div><div><br></div><div>Thanks.</div></div><div><br></div><div>cleo<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, Jul 30, 2014 at 11:15 AM, Jeremy Palmer <span dir="ltr"><<a href="mailto:JPalmer@linz.govt.nz" target="_blank">JPalmer@linz.govt.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-NZ" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hi Cleo,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Just been dealing with this type of issue.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">It’s likely that the byte datatype is overflowing.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Try something like:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">--calc "(A.astype(int)-B.astype(int))/(A.astype(int)+B.astype(int))"<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Actually you might only need to cast one of the bands from byte to int, so the syntax could be:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">--calc "(A.astype(int)-B A.astype(int)+B)"<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Cheers<br>
Jeremy<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:gdal-dev-bounces@lists.osgeo.org" target="_blank">gdal-dev-bounces@lists.osgeo.org</a> [mailto:<a href="mailto:gdal-dev-bounces@lists.osgeo.org" target="_blank">gdal-dev-bounces@lists.osgeo.org</a>]
<b>On Behalf Of </b>Cleo Drakos<br>
<b>Sent:</b> Wednesday, 30 July 2014 2:06 p.m.<br>
<b>To:</b> Vincent Schut<br>
<b>Cc:</b> gdal-dev<br>
<b>Subject:</b> Re: [gdal-dev] Does gdal_calc.py not calculate arithmetic with in the same file?<u></u><u></u></span></p><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Even if I converted the input file into Float 32 at first, the resulted image is still totally black.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><br clear="all">
<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">cleo<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Tue, Jul 29, 2014 at 11:20 PM, Vincent Schut <<a href="mailto:schut@sarvision.nl" target="_blank">schut@sarvision.nl</a>> wrote:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">On 07/29/2014 04:04 PM, Cleo Drakos wrote:<br>
<br>
<u></u><u></u></p>
<div>
<p class="MsoNormal">Thanks for your response. <u></u><u></u></p>
<div>
<p class="MsoNormal">I tried the followings:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">gcalc = 'C:\\Users\\cleo\\Documents\\gdalpys\\gdal_calc.py'<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">##I produced second file (b)as the copy of first(a)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">a = 'D:\\a.tif'<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">b = 'D:\\b.tif'<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">outfile = 'D:\\result.tif'<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">expr = '(A-B)/(A+B)'<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">subprocess.call([sys.executable,gcalc,'-A',a,'--A_band','1','-B',b,'--B_band','0','--outfile',outfile,\<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> '--calc',expr,'--type','Float32','--format','ENVI'],shell=True) <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">a,b,outfile = None, None,None<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Unfortunately, resulted file is completely black.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I hope someone can help me.<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">I don't use gdal_calc myself, but I suppose the problem is the byte datatype. I would try to convert the input data to float32 first (use gdal_translate -ot Float32) and try again.<br>
<br>
Best,<br>
Vincent.<u></u><u></u></p>
<div>
<p class="MsoNormal"><br>
<br>
<br>
<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Tue, Jul 29, 2014 at 10:37 PM, Etienne Tourigny <<a href="mailto:etourigny.dev@gmail.com" target="_blank">etourigny.dev@gmail.com</a>> wrote:<u></u><u></u></p>
<div>
<p class="MsoNormal">I am not sure, but you can do the following to make sure: <u></u>
<u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">cp infile infile2<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">gdal_calc.py -A infile --A_band 1 -B infile2 --B_band 0 --outfile outfile --calc "(A-B)/(A+B)" </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">Also, perhaps the extra comma in your command might be to blame "</span><span style="font-family:"Arial","sans-serif"">-B infile,"</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">Etienne</span><u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
<div>
<div>
<div>
<p class="MsoNormal">On Tue, Jul 29, 2014 at 3:46 AM, Cleo Drakos <<a href="mailto:cleo21drakos@gmail.com" target="_blank">cleo21drakos@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<div>
<p class="MsoNormal">Hi GDAL Developers,<br>
<br>
I have one GeoTIFF file with 2 bands. The data type is Byte. I want to calculate (Band2-Band1)/(Band2+Band1).<br>
<br>
But the following command provided a dark image:<br>
<br>
gdal_calc.py -A infile --A_band 1 -B infile, --B_band 0 --outfile outfile --calc "(A-B)/(A+B)"
<br>
<br>
Does gdal_calc.py not calculate arithmetic with in the same file?<br>
<br>
Thanks for your time.<span style="color:#888888"><br>
<br>
cleo</span><u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
<pre>_______________________________________________<u></u><u></u></pre>
<pre>gdal-dev mailing list<u></u><u></u></pre>
<pre><a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><u></u><u></u></pre>
<pre><a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><u></u><u></u></pre>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal"><br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
<br>
<hr>
<font face="Verdana" color="Black">This message contains information, which may be in confidence and may be subject to legal privilege. If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message. If
you have received this message in error, please notify us immediately (Phone 0800 665 463 or <a href="mailto:info@linz.govt.nz" target="_blank">info@linz.govt.nz</a>) and destroy the original message. LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from
LINZ. Thank You.<br>
</font>
</div>
</blockquote></div><br></div></div>