How to assign to each pixel of a raster value of the biggest difference between values of all pixels around it to a mask on 1 picture (red pixels and everything that after them is not included, black pixels and everything that inside of them are included).

Here is an example of how it works on 2 picture. I wrote such pseudo-code with Python assuming that as input i get list with all closest pixels using as a Central pixel lower left a corner 2 pictures of the. I do not understand how this can be transformed into a script for QGIS or Raster Calculator.

I tried in R the neighbour's module, but every time I set a radius greater than or less than 3 it throws an error. Also, you can take pixels not only for this mask but also for a circular radius of 128 meters. (For images of Landsat with a spatial resolution of 30x30). With what should I implement this?

near_pixels_list = [4,
                    1, 3, 3, 5,
                    8, 4, 1, 3,
                    0, 0, 7, 7,
                    4, 3, 0, 2, 1]
center_pixel = 4
output = max(list(map(lambda x: max(center_pixel, x) - min(center_pixel, x), near_pixels_list)))



  • Sorry, I'm from Russia, that's why my English is so bad. I would be very grateful if edit grammar and everything else. Dec 18 '19 at 10:08
  • Don't worry for your english but please translate the title of your question, you will be more likely to get answer with a clear title
    – J.R
    Dec 18 '19 at 10:13

I think you first need Maximum and Minimum values from focal statistics in the 128m-radius window.

Only tool which supports circle window (as far as I know) is SAGA Residual analysis tool in Processing Toolbox > SAGA > Geostatistics. Settings are:

  • Search Mode: [1] circle
  • Radius (Cells) : 4 ( 4 * 30m = 120m, which is equivalent to your 128m radius)
  • Include Center Cell: Leave it on (it does not work... and has no effect on the result)
  • Distance Weighting: [0] no distance weighting

You will have many outputs, but you just need Maximum and Minimum. Then subtract Minimum from Maximum raster to get the desired result.

enter image description here

  • Thanks, this works, but 3 pixels(120 meters) is not equal to 128 meters radius, so I need that between the center pixel and the capture pixel could fit 2 pixels diagonally. Dec 19 '19 at 12:22

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.