0

How can I write a 2D gaussian cumulative matlab function that gets applied to an input 2D binary image. The mean of the gaussian cumulative is on a particular selected curved line which will be given as an input. So the inputs of the function is:

  1. The main 2D binary image.
  2. A 2D binary matrix with the same size as the main 2D binary image which is 1 where the 2D gaussian cumulative function’s means should be, and 0 everywhere else.
  3. The standard deviation of the 2D Gaussian cumulative function

And the output is the smoothed form of the main 2D binary image

I have tried this code but its all wrong:

function [smoothed_image] = gaussian_cumulative_2D(binary_image, mean_loop, std_dev)

% Create a meshgrid for the x and y coordinates
[x,y] = meshgrid(1:size(binary_image,2), 1:size(binary_image,1));

% Calculate the distance from each point to the mean loop
distance = sqrt((x-mean_loop(1)).^2 + (y-mean_loop(2)).^2);

% Calculate the gaussian cumulative function
gaussian_cumulative = 0.5*(1 + erf(distance/(std_dev*sqrt(2))));

% Apply the gaussian cumulative function to the binary image
smoothed_image = binary_image.*gaussian_cumulative;

end
Adriaan
  • 17,741
  • 7
  • 42
  • 75
Sam
  • 1
  • What is a “2D Gaussian cumulative function”? Is this the 2D integral of a 2D Gaussian? Or is it something else? What you compute as `gaussian_cumulative` is the 1D integral of a 1D Gaussian. What is “apply” in this context? You are multiplying the image by the `gaussian_cumulative` map you created. Maybe you need to compute a convolution? To smooth an image you’d convolve it with a smoothing kernel, such as a Gaussian. A convolution with an error function would be… uncommon. – Cris Luengo Apr 18 '23 at 17:44

0 Answers0