<html>
<head>
<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>
</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);">
There is a <code>band_nums</code> parameter (and weights) you can provide to <code>
gdal_pansharpen</code>, which led to me thinking about this question in the first place.</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>
<pre style="margin: 0px;"><div class="elementToProof" style="text-align: left; text-indent: 0px; line-height: var(--jp-code-line-height); white-space: pre-wrap; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">band_nums: Optional[Sequence[int]] = None</div></pre>
<pre style="margin: 0px;"><div style="text-align: left; text-indent: 0px; line-height: var(--jp-code-line-height); white-space: pre-wrap; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">weights: Optional[Sequence[float]] = None</div></pre>
<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);">
So, providing either <code>band_nums=[1,2,3,4]</code> along with weights and extracting bands 1 and 4 after-the-fact, or
<code>band_nums=[1,4] and </code><code style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif;">providing the corresponding weights for those bands, in my mind should produce something similar? I haven't tried it
just yet.</code></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> Barry DeZonia <bdezonia@gmail.com><br>
<b>Sent:</b> Thursday, January 9, 2025 14:04<br>
<b>To:</b> Even Rouault <even.rouault@spatialys.com><br>
<b>Cc:</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 class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">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.<br>
<br>
<br>
<br>
<br>
<br>
Does that snippet of code need to be that way? It seems it could<br>
pretty easily be changed to work a band at a time and a weight of zero<br>
would contribute nothing. Now I do not know the domain at all and<br>
maybe that violates some assumptions. Curious as to what you think.<br>
<br>
On Thu, Jan 9, 2025 at 2:36 PM Even Rouault via gdal-dev<br>
<gdal-dev@lists.osgeo.org> wrote:<br>
><br>
><br>
> Le 09/01/2025 à 20:27, Joe McGlinchy via gdal-dev a écrit :<br>
><br>
> Hello,<br>
><br>
> 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?<br>
><br>
> Given the formula at <a 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><br>
><br>
> pseudo_panchro[pixel] = sum(weight[i] * spectral[pixel][i] for i=0 to nb_spectral_bands-1)<br>
> ratio = panchro[pixel] / pseudo_panchro[pixel]<br>
> for i=0 to nb_spectral_bands-1:<br>
> output_value[pixel][i] = input_value[pixel][i] * ratio<br>
><br>
><br>
> 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.<br>
><br>
><br>
> If your spectral dataset has bands in the R,G,B,NIR order, you can achieve what you want with:<br>
><br>
><br>
> $ 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>
> Even<br>
><br>
> --<br>
> <a href="http://www.spatialys.com">http://www.spatialys.com</a><br>
> My software is free, but my time generally not.<br>
> Butcher of all kinds of standards, open or closed formats. At the end, this is just about bytes.<br>
><br>
> _______________________________________________<br>
> gdal-dev mailing list<br>
> gdal-dev@lists.osgeo.org<br>
> <a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</div>
</span></font></div>
</body>
</html>