<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 style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Even,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
thanks for your response. I will try to test this with the updated code, although I have yet to learn the compilation process.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I will let you know if I am able to verify this is fixed<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background: var(--white);">.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background: var(--white);">
<div style="margin:0px;font-size:12pt;color:black"></div>
<div style="margin:0px;font-size:12pt;color:black"><br>
</div>
<div style="margin:0px;font-size:12pt;color:black">All the best,</div>
<div style="margin:0px;font-size:12pt;color:black"> — Brendan Heberlein</div>
<div style="margin:0px;font-size:12pt;color:black">
<div style="margin:0px;font-size:15px;color:rgb(32, 31, 30)"><span style="margin:0px;font-size:10pt"> Research Intern, BS</span></div>
<div style="margin:0px;font-size:15px;color:rgb(32, 31, 30)"><span style="margin:0px;font-size:10pt"> Townsend Lab</span></div>
<span style="margin:0px;font-size:10pt;color:rgb(32, 31, 30);background-color:white"> University of Wisconsin - Madison</span></div>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background: var(--white);"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background: var(--white);"><br>
</span></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> Friday, June 11, 2021 2:49 PM<br>
<b>To:</b> Brendan Heberlein <bheberlein@wisc.edu>; gdal-dev@lists.osgeo.org <gdal-dev@lists.osgeo.org><br>
<b>Subject:</b> Re: [gdal-dev] Edge Artifacts with GDAL Warp & Geolocation Arrays</font>
<div> </div>
</div>
<div>
<p>Hi,</p>
<p><br>
</p>
<p>I believe <a class="x_moz-txt-link-freetext" href="https://github.com/OSGeo/gdal/pull/3964">
https://github.com/OSGeo/gdal/pull/3964</a> should improve this</p>
<p><br>
</p>
<p>Even<br>
</p>
<p><br>
</p>
<div class="x_moz-cite-prefix">Le 11/06/2021 à 21:30, Brendan Heberlein 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 style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">Hello all,</span><br>
</div>
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I have been using <code>gdalwarp</code> to georeference sensor data with geolocation arrays.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I have observed that GDAL assigns values to pixels that clearly fall outside the geolocation footprint, producing some funny artifacts at the image edges. For example,
<a href="https://pasteboard.co/K69DUni.png" title="https://pasteboard.co/K69DUni.png">
see the image here</a>.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
(Sensor data over Google satellite basemap; red dots are geolocation points.)</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Notice how the data values are 'extruded' from the edges.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
This occurs with various interpolation methods (all the ones I tried), including nearest neighbor, average & bilinear. Why does this happen? How can I go about fixing this?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Ideally, any pixel in the output grid which lies more than 1 pixel width from any of the geolocation points (red dots) would be assigned to no-data.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
My code is very straightforward, basically I open the raw sensor image & geolocation array (a.k.a. input geometry map or IGM) with GDAL & then assign geolocation metadata to the sensor image before warping:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<blockquote itemscope="" itemtype="https://schemas.microsoft.com/QuotedText" style="border-left-width:3px; border-left-style:solid; border-color:rgb(200,200,200); padding-left:1ex; margin-left:0.8ex; color:rgb(102,102,102)">
<span style="font-family:Consolas,Courier,monospace; font-size:10pt"># Geolocation domain metadata</span>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">geoloc_metadata = {</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> 'SRS': WGS84_UTM16N.ExportToWkt(),</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> 'X_BAND': '1',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> 'X_DATASET': str(igm_img_file),</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> 'Y_BAND': '2',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> 'Y_DATASET': str(igm_img_file),</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> 'PIXEL_OFFSET': '0',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> 'LINE_OFFSET': '0',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> 'PIXEL_STEP': '1',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> 'LINE_STEP': '1',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">}</span></div>
<div><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"># Set geolocation domain metadata on dataset to be warped</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">dn_img_ds.SetMetadata(geoloc_metadata, 'GEOLOCATION')</span></div>
<div><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">x_min, y_min = igm[:2].min(axis=(1,2))</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">x_max, y_max = igm[:2].max(axis=(1,2))</span></div>
<div><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"># warp_options = gdal.WarpOptions(warpMemoryLimit=)</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">warped_ds = gdal.Warp(f'/warped.tif', dn_img_ds,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"><span style="background-color:rgb(255,255,255); display:inline!important"> <span class="x_x_Apple-converted-space"> </span></span>outputBounds=(x_min, y_min, x_max,
y_max),</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> xRes=1.0,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> yRes=1.0,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> resampleAlg='near',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> dstSRS=WGS84_UTM16N,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> srcNodata=None,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> dstNodata=-9999,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> multithread=True,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> targetAlignedPixels=True,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> outputType=get_gdal_dtype(np.int16),</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"> geoloc=True)</span></div>
</blockquote>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
Any insight would be much appreciated. Cheers!</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
— Brendan Heberlein</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div style="margin:0px; font-size:15px; color:rgb(32,31,30)"><span style="margin:0px; font-size:10pt"> Research Intern, BS</span></div>
<div style="margin:0px; font-size:15px; color:rgb(32,31,30)"><span style="margin:0px; font-size:10pt"> Townsend Lab</span></div>
<span style="margin:0px; font-size:10pt; color:rgb(32,31,30); background-color:white"> University of Wisconsin - Madison</span></div>
</div>
<br>
<fieldset class="x_mimeAttachmentHeader"></fieldset>
<pre class="x_moz-quote-pre">_______________________________________________
gdal-dev mailing list
<a class="x_moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>
<a class="x_moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</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.</pre>
</div>
</body>
</html>