# Find most contrast pixel on raster in certain range of pixels around it?

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

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)
• Distance Weighting: `[0] no distance weighting`