<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thank you, Even!</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);">
In the event that we are provided only 4 bands, but from an 8-band system, will this still hold? It is what we have to work with, unfortunately or not.</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);">
-Joe</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Even Rouault <even.rouault@spatialys.com><br>
<b>Sent:</b> Thursday, January 9, 2025 13:24<br>
<b>To:</b> Joe McGlinchy <joe@aidash.com>; gdal-dev@lists.osgeo.org <gdal-dev@lists.osgeo.org><br>
<b>Subject:</b> Re: [gdal-dev] pansharpen subset of multispectral bands</font>
<div> </div>
</div>
<div>
<p style="text-align:justify"><span style="color:#ff0000">EXTERNAL SENDER. DO NOT click links, or open attachments, if the sender is unknown, or the message seems suspicious in any way. DO NOT provide your user ID or Password.</span></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"> </p>
<div>
<p><br>
</p>
<div class="x_moz-cite-prefix">Le 09/01/2025 à 20:27, Joe McGlinchy via gdal-dev a écrit :<br>
</div>
<blockquote type="cite"><style type="text/css" style="display:none">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div class="x_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="x_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="x_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="x_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="x_n">pseudo_panchro</span><span class="x_p">[</span><span class="x_n">pixel</span><span class="x_p">]</span> <span class="x_o">=</span> <span class="x_nb">sum</span><span class="x_p">(</span><span class="x_n">weight</span><span class="x_p">[</span><span class="x_n">i</span><span class="x_p">]</span> <span class="x_o">*</span> <span class="x_n">spectral</span><span class="x_p">[</span><span class="x_n">pixel</span><span class="x_p">][</span><span class="x_n">i</span><span class="x_p">]</span> <span class="x_k">for</span> <span class="x_n">i</span><span class="x_o">=</span><span class="x_mi">0</span> <span class="x_n">to</span> <span class="x_n">nb_spectral_bands</span><span class="x_o">-</span><span class="x_mi">1</span><span class="x_p">)</span>
<span class="x_n">ratio</span> <span class="x_o">=</span> <span class="x_n">panchro</span><span class="x_p">[</span><span class="x_n">pixel</span><span class="x_p">]</span> <span class="x_o">/</span> <span class="x_n">pseudo_panchro</span><span class="x_p">[</span><span class="x_n">pixel</span><span class="x_p">]</span>
<span class="x_k">for</span> <span class="x_n">i</span><span class="x_o">=</span><span class="x_mi">0</span> <span class="x_n">to</span> <span class="x_n">nb_spectral_bands</span><span class="x_o">-</span><span class="x_mi">1</span><span class="x_p">:</span>
    <span class="x_n">output_value</span><span class="x_p">[</span><span class="x_n">pixel</span><span class="x_p">][</span><span class="x_n">i</span><span class="x_p">]</span> <span class="x_o">=</span> <span class="x_n">input_value</span><span class="x_p">[</span><span class="x_n">pixel</span><span class="x_p">][</span><span class="x_n">i</span><span class="x_p">]</span> <span class="x_o">*</span> <span class="x_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"></blockquote>
<pre class="x_moz-signature" cols="72">-- 
<a class="x_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>
</div>
</div>
</body>
</html>