I have a set of rasters in which I want to replace any rgb value of (0,0,0) with (nodata,nodata,nodata)

I've tried using

gdal_translate -a_nodata "0,0,0" in.tif out.tif

But this seems to convert all 0s to nodata, for example (0,10,10) becomes (nodata,10,10). I want these to stay the same and only convert (0,0,0) to (nodata,nodata,nodata).

I'm looking for any solutions using gdal tools like gdal_translate or gdalwarp that I can add into a larger shell script.

closed as off-topic by PolyGeo Mar 10 '17 at 3:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Try gdalwarp with -srcnodata "0,0,0" -dstnodata "0,0,0". – user30184 Oct 15 '15 at 20:24
  • Thanks but this still seems to replace cells like (0,10,10) with (nodata,10,10). I need these to stay the same. – jamaps Oct 15 '15 at 20:48
  • Try if alpha channel works better. And by the way, which GDAL version you have? Should have asked that first. – user30184 Oct 15 '15 at 20:49
  • 1
    osgeo-org.1560.x6.nabble.com/…. Try gdalwarp with warping option UNIFIED_SRC_NODATA=YES – user30184 Oct 15 '15 at 20:56
  • Thanks for the suggestion and sorry for the delay. I was able to solve this (for my purposes) with gdalwarp -srcnodata None -dstnodata None -dstalpha This seems to hide the (0,0,0) values when viewing in QGIS rather than converting them. – jamaps Oct 21 '15 at 14:42