3

How can I change the pixel value from 0 to 10 on QGIS?

enter image description here

6
  • Use raster calculator. – user30184 Feb 22 at 10:04
  • If you would like to change all zeros to ten in your raster then you can use raster calculator. To change a single pixel value you need gimp or similar image manipulation program. – Zoltan Feb 22 at 10:14
  • I would like to change all 0 values to 10. How can I write this into the Raster Calculator? Thank you very much – Leonardo Feb 22 at 10:20
  • 1
    Please try ("YourRaster@1" = 0) * 10 + ("YourRaster@1" != 0) * ("YourRaster@1") – Kazuhito Feb 22 at 11:02
  • 1
    Glad it workd. Let me post it as an answer. – Kazuhito Feb 22 at 11:35
6

Allow me to rephrase the question "change the pixel value from 0 to 10" as follows;

  • if the pixel value equals 0, then change it to 10.
  • if the pixel value is not 0, then keep the original pixel value.

(1) The first one is expressed as ("YourRaster@1" = 0) * 10.

  • (A) when the pixel value is 0, condition ("YourRaster@1" = 0) returns True which is 1. Then 1 * 10 becomes 10.
  • (B) when the pixel value is not 0, condition ("YourRaster@1" = 0) returns False which is 0. Then 0 * 10 becomes 0.

(2) The second one is expressed as ("YourRaster@1" != 0) * ("YourRaster@1").

  • (C) when the pixel value is 0, condition ("YourRaster@1" != 0) returns False. Then 0 * ("YourRaster@1") becomes 0.
  • (D) when the pixel value is not 0, condition ("YourRaster@1" != 0) returns True. Then 1 * ("YourRaster@1") becomes ("YourRaster@1") (i.e. your original pixel value).

(3) Finally, by putting these two together, ("YourRaster@1" = 0) * 10 + ("YourRaster@1" != 0) * ("YourRaster@1") will work this way:

  • When the pixel value is 0, (A) + (C) becomes 10 + 0, which is 10.
  • When the pixel value is not 0, (B) + (D) becomes 0 + "YourRaster@1", which is the pixel value of your original raster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.