Search code examples
imagematlabimage-processinggradientedge-detection

Generation of edge stop parameter according to self-snake model in MATLAB


I want to generate an edge stop parameter according to the self snake model by G. Sapiro to remove multiplicative noise. The function is g(r) = 1/(1+(r/k)^2), where r is magnitude of ∇u. u is the actual image. My code is as follows

[GradientX,GradientY] = gradient(double(originimg));
Gr = sqrt((GradientX.*GradientX)+(GradientY.*GradientY));
[X1, Y1]=size(Gr);
for i=1:X1
    for j=1:Y1
        r = mean(Gr(i,:));
    end
end
stParam = 1 / (1 + ((r / gradTP)^2));

value of gradTP=1.

But I'm not getting the expected result. Actually it is giving a matrix as the result, but according to the paper I'm following, the parameter must be a scalar. Please suggest some way out. Thanks in advance.


Solution

  • From your comments, you said you want to find the gradient of the overall image. I'm assuming you mean to compute one magnitude value for the entire image. One way to do it is perhaps to find the average magnitude value. That can be done by simply finding the overall mean of Gr. You can then use that to plug into your formula to get your result.

    As such, try something like this:

    [GradientX,GradientY] = gradient(double(originimg));
    Gr = sqrt((GradientX.*GradientX)+(GradientY.*GradientY));
    
    %// Change
    r = mean(Gr(:));
    
    stParam = 1 / (1 + ((r / gradTP)^2));