<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div class="">Hi,</div>
<div class=""><br class="">
</div>
<div class="">Sorry to answer that now I have not had the notification ... (it was in my spam)</div>
<div class=""><br class="">
</div>
<div class="">I used software to binarize my png which allowed me to carry out my project until the end.</div>
<div class=""><br class="">
</div>
<div class="">But I like the idea of being able to process this via a script.</div>
<div class="">I have a script_list.sh which contains a script_file.sh for each tile which allows me to automate the tasks for the 512 tiles.</div>
<div class="">I will test your solution and incorporate it as soon as I have time (I want to finalize the last things I have left before) and I will keep you posted.</div>
<div class=""><br class="">
</div>
<div class="">I'm on mac but I installed gawk and gsed (awk and sed are different on macOS)</div>
<div class=""><br class="">
</div>
<div class="">Thanks again for the code on github ;)</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">Le 3 janv. 2020 à 01:42, <a href="mailto:lars.schylberg@blixtmail.se" class="">
lars.schylberg@blixtmail.se</a> a écrit :</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">
<div data-html-editor-font-wrapper="true" style="font-family: arial, sans-serif; font-size: 13px;" class="">
Hi,<br class="">
<br class="">
There is one way to solve this with gdal_calc. I have had some time off during the holidays,<br class="">
but kept thinking about your question and thought it was a fun problem.<br class="">
Actually I have solved some other problems with tif palette images and gdal_calc lately. So I put together one solution that<br class="">
I think will work in your case. I am assuming that You are using linux and have some knowledge in bash scripting.<br class="">
<br class="">
First we have to create a reclass rule for gdal_calc, We do that with with running gdalinfo.
<br class="">
Strip the info to only keep the color table with sed.<br class="">
Then dynamically create the rule with awk, based on your rgb values (turn palette values into either 0 or 1).<br class="">
Finally strip the last "+" from the rule (the last sed command)<br class="">
<br class="">
Then run gdal_calc with your relclass rule<br class="">
<br class="">
gdal_calc produces a grey scale image, but:<br class="">
<br class="">
We then turn the image into a virtual raster file (VRT)<br class="">
We create a new color table and insert it into the vrt file with sed.<br class="">
Change the vrt file to be a palette image again with sed.<br class="">
Finally we can turn the vrt image into a tif image again.<br class="">
<br class="">
If this works you could loop over all your images and process all in the same way.<br class="">
Just do a bash function with the steps and loop over your input files.<br class="">
<br class="">
The whole idea of the process is outlined in a gist I just uploaded.<br class="">
I just tested the first part with the rule myself, but the other stuff I used before<br class="">
so it should work.<br class="">
<br class="">
<a href="https://gist.github.com/LarsSchy/c1be96fa03f7dc11df4247be033e2705" class="">https://gist.github.com/LarsSchy/c1be96fa03f7dc11df4247be033e2705</a><br class="">
<br class="">
I hope this helps You. <br class="">
<br class="">
Have fun / Lars Schylberg<br class="">
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</body>
</html>