-1

I have an 450x450 gray image. The neighbourhood of each pixel to be processed is defined by the Euclidean distance based on two radii, R1 and R2. Hence:

  • All pixels in the neighbourhood of R1 and R2 should be summed respectively.
  • Each pixel mapped to R1 and R2 should be counted each pass.
  • New Image should be ratio of these two regions: sum of pixels mapped to R1*Counter2 / sum of pixels mapped to R2*Counter1.

How can I do this in MATLAB?

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
bstar
  • 109
  • 7

1 Answers1

1

A neighborhood within Euclidean distance R1 can be obtained as follows:

[x,y] = meshgrid(-R1:R1,-R1:R1);
r = x.^2 + y.^2;
k1 = r < R1.^2;

A convolution with this kernel leads to, for each output pixel, the sum of the pixels in its neighborhood:

sum1 = conv2(img, k1);

(where img is your image -- do make sure it is of a floating-point type, if it is of an integer type it is possible that the result of the sum cannot be represented correctly).

You can repeat the same code above for R2, leading to sum2, and then compute your ratio:

result = sum1 ./ sum2;
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120