<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">Le 09/01/2025 à 20:27, Joe McGlinchy
via gdal-dev a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:MW6PR04MB887175123CA3077AF03288C4C3132@MW6PR04MB8871.namprd04.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
<div class="elementToProof"
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hello,</div>
<div class="elementToProof"
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof"
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I'm wanting to pansharpen only a subset of multispectral bands I
have available. Say for instance I have blue-green-red-nir, and
a panchromatic band, I can calculate the relative weights to
specify when using `gdal_pansharpen` on the full multispectral
dataset. If I want to only pansharpen, for example, the red and
NIR bands, is it best to perform the pansharpening on the full
dataset and only retain the bands I need? Or can i provide only
the weights specific to the bands I want to pansharpen? If I can
do the latter (which I can, given the parameter set to
`gdal_pansharpen`), do I need to recalculate those weights, or
only provide the subset of weights for those specific bands?</div>
</blockquote>
<p>Given the formula at
<a class="moz-txt-link-freetext"
href="https://gdal.org/en/stable/drivers/raster/vrt.html#gdal-vrttut-pansharpen">https://gdal.org/en/stable/drivers/raster/vrt.html#gdal-vrttut-pansharpen</a></p>
<pre><span class="n">pseudo_panchro</span><span class="p">[</span><span
class="n">pixel</span><span class="p">]</span> <span class="o">=</span> <span
class="nb">sum</span><span class="p">(</span><span class="n">weight</span><span
class="p">[</span><span class="n">i</span><span class="p">]</span> <span
class="o">*</span> <span class="n">spectral</span><span class="p">[</span><span
class="n">pixel</span><span class="p">][</span><span class="n">i</span><span
class="p">]</span> <span class="k">for</span> <span class="n">i</span><span
class="o">=</span><span class="mi">0</span> <span class="n">to</span> <span
class="n">nb_spectral_bands</span><span class="o">-</span><span
class="mi">1</span><span class="p">)</span>
<span class="n">ratio</span> <span class="o">=</span> <span class="n">panchro</span><span
class="p">[</span><span class="n">pixel</span><span class="p">]</span> <span
class="o">/</span> <span class="n">pseudo_panchro</span><span
class="p">[</span><span class="n">pixel</span><span class="p">]</span>
<span class="k">for</span> <span class="n">i</span><span class="o">=</span><span
class="mi">0</span> <span class="n">to</span> <span class="n">nb_spectral_bands</span><span
class="o">-</span><span class="mi">1</span><span class="p">:</span>
<span class="n">output_value</span><span class="p">[</span><span
class="n">pixel</span><span class="p">][</span><span class="n">i</span><span
class="p">]</span> <span class="o">=</span> <span class="n">input_value</span><span
class="p">[</span><span class="n">pixel</span><span class="p">][</span><span
class="n">i</span><span class="p">]</span> <span class="o">*</span> <span
class="n">ratio</span>
</pre>
<p><br>
</p>
<p>if you only provide a subset of the input spectral bands, you
won't be able to reconstruct a plausible pseudo_panchro values,
hence the scaling ratio will not be accurate.</p>
<p><br>
</p>
<p>If your spectral dataset has bands in the R,G,B,NIR order, you
can achieve what you want with:<br>
</p>
<p><br>
</p>
<p>$ gdal_pansharpen panchro.tif rgbnir.tif,band=1 rgbnir.tif,band=2
rgbnir.tif,band=3 rgbnir.tif,band=4 out.tif -b 1 -b 4<br>
<br>
</p>
<p>Even</p>
<span style="white-space: pre-wrap">
</span>
<blockquote type="cite"
cite="mid:MW6PR04MB887175123CA3077AF03288C4C3132@MW6PR04MB8871.namprd04.prod.outlook.com">
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.
Butcher of all kinds of standards, open or closed formats. At the end, this is just about bytes.</pre>
</body>
</html>