<div dir="ltr"><div>In addition to all the previous, what about gamma correction?</div><div>Maybe your RGB images are gamma corrected, while the other bands are not. In that case you will be comparing apples and oranges (in addition to the scaling problems described before).</div><div>That also means that using the multispectral images (even if you had a Blue one) without gamma correction will have a strange color for us humans using a monitor.</div><div><br></div><div>What I did in the past was to "fake" blue as a combination of red and green (yes, it is not perfect, but better than nothing), and apply a gamma of 2 to all the bands.</div><div><br></div><div>Other "nice" option is to display them as CIR <a href="https://www.mngeo.state.mn.us/chouse/airphoto/cir.html">https://www.mngeo.state.mn.us/chouse/airphoto/cir.html</a></div><div><br></div><div>Cheers</div><div>Javier<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 22 Apr 2024 at 17:49, Andrew C Aitchison via gdal-dev <<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, 22 Apr 2024, Raley, Nathan via gdal-dev wrote:<br>
<br>
> Hmm, good catch.  Looking at the stats for the red band:<br>
><br>
> Band 1 Block=128x128 Type=UInt16, ColorInterp=Gray<br>
>  Min=130.000 Max=36265.000<br>
>  Minimum=130.000, Maximum=36265.000, Mean=10415.962, StdDev=3502.933<br>
>  NoData Value=0<br>
>  Metadata:<br>
>    STATISTICS_MAXIMUM=36265<br>
>    STATISTICS_MEAN=10415.961859513<br>
>    STATISTICS_MINIMUM=130<br>
>    STATISTICS_STDDEV=3502.9325925887<br>
>    STATISTICS_VALID_PERCENT=49<br>
><br>
> So, is there no way to actually do this via command line, or am I going to have to write a python lib to actually read through these and determine what they should be scaled to?<br>
<br>
There is gdal_transform -scale (and -scale_2 etc.)<br>
<br>
What are you going to do with the resulting file ?<br>
QGIS allows you to make these sorts of adjustments at view-time.<br>
<br>
Remember that the max and min values present in an image may not represent<br>
the full range and the next-door image may have a larger or smaller range<br>
(or just a shifted range). Imagine a row of three tiles; the middle on on <br>
the edge of a glacier, the first entirely on the glacier and the last <br>
entirely off the glacier. You may wish to apply the same scaling to all <br>
three.<br>
<br>
> From: Daniel Evans <<a href="mailto:daniel.fred.evans@gmail.com" target="_blank">daniel.fred.evans@gmail.com</a>><br>
> Sent: Monday, April 22, 2024 9:29 AM<br>
> To: Raley, Nathan <<a href="mailto:nraley@gaig.com" target="_blank">nraley@gaig.com</a>><br>
> Cc: '<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>' (<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>) <<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>><br>
> Subject: [External] Re: [gdal-dev] Question on building multi band composite and going back to RGB GeoTiff<br>
><br>
> Hi Nathan, My initial suspicion might just be that the scaling the data provider did to go from the raw data to a human-eye-friendly RGB composite isn't the conversion you're assuming. I know that with the data I regularly work with,<br>
><br>
> Hi Nathan,<br>
><br>
> My initial suspicion might just be that the scaling the data provider did to go from the raw data to a human-eye-friendly RGB composite isn't the conversion you're assuming.<br>
><br>
> I know that with the data I regularly work with, it may be provided as Uint16, but the data range doesn't extend all the way to 65535.<br>
><br>
> If you compare the values in the separate R and G images to the RGB composite, do they appear to match the conversion you're assuming, or is there a different scaling (and possibly offset)?<br>
><br>
> Cheers,<br>
> Daniel<br>
><br>
> On Mon, 22 Apr 2024, 15:20 Raley, Nathan via gdal-dev, <<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><mailto:<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>>> wrote:<br>
> I currently have a RGB geotiff composite image that has a Byte datatype.  I also have individual band images for R, G, Redge, and NIR that are UInt16 datatypes.  Since I’m missing the Blue band from the individual bands, I was attempting to extract the blue band from the RGB composite image, scale it up to the UInt16 datatype, and build a composite VRT with R, G, B, NIR, RE bands included in it.  I was then attempting to extract the RGB bands from the multispec VRT in order to see if the process was working as intended, but I’m getting an extremely blue image.<br>
><br>
> Can anyone shed some light as to what I may be doing wrong here?<br>
><br>
> I started by building a VRT for each band:<br>
> gdal_translate source_RGB.tif b.vrt -ot UInt16 -of VRT -b 3 -scale 0 255 0 65535<br>
> gdalbuildvrt -b 1 r.vrt source_R.tif<br>
> gdalbuildvrt -b 1 g.vrt source_G.tif<br>
> gdalbuildvrt -b 1 nir.vrt source_NIR.tif<br>
> gdalbuildvrt -b 1 re.vrt source_RE.tif<br>
><br>
> I then merged the VRTs:<br>
> gdalbuildvrt -separate multispec.vrt r.vrt g.vrt b.vrt nir.vrt re.vrt<br>
><br>
> I now have a multispec.vrt with the R, G, B, NIR, and RE bands, all with a UInt16 datatype.<br>
><br>
> Now, I attempted to rebuild a RGB GeoTiff from the composite VRT with something like:<br>
> gdal_translate -ot Byte -of GTiff -b 1 -b 2 -b 3 -scale 0 65535 0 255 -co PHOTOMETRIC=RGB multispec.vrt multispec.tif<br>
><br>
> Viewing the result in QGIS appears overly blue.  What am I doing wrong here?<br>
><br>
> Thanks,<br>
> Nathan<br>
><br>
> ________________________________<br>
> This email transmission, including any attachments, is intended solely for the addressee named above, and may contain confidential or privileged information. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender immediately by reply email and destroy the message and its attachments.<br>
> _______________________________________________<br>
> gdal-dev mailing list<br>
> <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><mailto:<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>><br>
> <a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><<a href="https://urldefense.com/v3/__https:/lists.osgeo.org/mailman/listinfo/gdal-dev__;!!CsmrWXz9mOkSc4Hdn1fjj00!wHjHtqIprjw9nQ3elKNFMUWmEwR3sKx-zrxpsNEk-kBIhomauYshqPep8-beAmn7Ma8NlmL95Mqf9c8fol37c2o$" rel="noreferrer" target="_blank">https://urldefense.com/v3/__https:/lists.osgeo.org/mailman/listinfo/gdal-dev__;!!CsmrWXz9mOkSc4Hdn1fjj00!wHjHtqIprjw9nQ3elKNFMUWmEwR3sKx-zrxpsNEk-kBIhomauYshqPep8-beAmn7Ma8NlmL95Mqf9c8fol37c2o$</a>><br>
><br>
> This email transmission, including any attachments, is intended solely for the addressee named above, and may contain confidential or privileged information. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender immediately by reply email and destroy the message and its attachments.<br>
><br>
<br>
-- <br>
Andrew C. Aitchison                      Kendal, UK<br>
                    <a href="mailto:andrew@aitchison.me.uk" target="_blank">andrew@aitchison.me.uk</a>_______________________________________________<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="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote></div>