3

I have a noise image I such as the bellow figure. Assume that it is Gaussian noise. Currently, I am using two steps to find the edge

  1. Smooth the image using Gaussian filter G
  2. Find edge based on the equation

    g=1/(1+β∇ (I*G)^2)

where G is gaussian filter. β is weight to control the noise level.

However, the Gaussian filter is reason for losing of edge in image. I want to find a better method that can preserve edge information. Could you suggest to me the best method to find the edge of that image?

This is my result for above steps

enter image description here

Here's the image I am working on with the noise added:

enter image description here

To get the edges, this is the MATLAB code I wrote:

beta=0.01;
G = fspecial('gaussian',[3 3],1);
I_G = conv2(I,G,'same');
[Gx,Gy] = gradient(I_G);
NormGrad = sqrt(Gx.^2 + Gy.^2); 
g = 1./ (1 + beta* NormGrad.^2);
imshow(g,[]);
rayryeng
  • 102,964
  • 22
  • 184
  • 193
user3051460
  • 1,455
  • 22
  • 58

2 Answers2

5

Canonical edge-preserving smoothing filters should be quite adequate for your particular application. These simultaneously remove noise (Gaussian distributed I should add...) while maintaining edges as best as possible. Classic examples include the bilateral filter, the Guided image filter by Kaiming He, Domain Transform filtering by Gastal and Oliveira (which I have successfully used in the past) and even anisotropic diffusion.

To try something quickly, the Guided image filter is now included as an official function that's part of the image processing toolbox since MATLAB R2014a via the imguidedfilter function. If you don't have MATLAB R2014a or up, then you can download the raw MATLAB source of the code via this link here: http://kaiminghe.com/eccv10/guided-filter-code-v1.rar, but you can get this from the main website I linked to you above.

Assuming you don't have R2014a, download the Guided image filter code and let's use it to filter your example. Given your link to the example image that was corrupted with noise, I downloaded it and am using it in the code below:

I = im2double(imread('https://i.stack.imgur.com/ACRE8.png')); %// Load in sample image that was corrupted by noise
r = 2; %// Parameters for the Guided image filter
eps = 0.1^2;

%// Filter the image, using itself as a guide
q = guidedfilter(I, I, r, eps);

%// Show the original image and the filtered result
figure;
subplot(1,2,1); imshow(I, []);
subplot(1,2,2); imshow(q, []);

We show the original image, then the guided filter result on the right:

enter image description here

Once we have that, try using any canonical edge detector to detect the edges. The one you're using pre-blurs the image before finding the edges, but that uses standard smoothing and it will miss out on some edges. Because using the Guided image filter brings us to a point where the edges are maintained and the overall image is essentially noise free, we can try something simple like a Sobel filter on the edge smoothed result:

[Gmag,~] = imgradient(q, 'sobel');
imshow(max(Gmag(:)) - Gmag,[]);

The above code uses imgradient to find image gradients and then we show the image by inverting the intensities so that the black values become white and white become black as seen in your example.

... and we get this:

enter image description here

As you can see, even with the presence of noise, we still were able to hammer out a lot of the edges.

rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • Thank rayryeng. I look at my result and your result and saw that your result is quite better than my result. However, we need some prove that your method can achieve edge preserving. Do you know any quantitative measurement to show that your method is better than my method? – user3051460 Aug 13 '15 at 19:08
  • 1
    There are a bunch of quantitative measures that you can use to determine whether one result is better than the other, but that requires that you have reference to the original edge image. If you don't have that, then you can only look at it qualitatively. Supposing you had a reference, you can use PSNR, MSE or any of its related ilk. That being said, without a reference to compare to, you can't compare between my method and your's. – rayryeng Aug 13 '15 at 19:10
  • @Benoit_11 - Merci :) – rayryeng Aug 13 '15 at 19:20
  • I have made a ref edge from segmented image (4 labels) using Laplacian. You can download at https://www.dropbox.com/s/4feqixaiby3zgky/Edges_invert.mat?dl=0 or if you want to create by yourself. You can download the segmented image at https://www.dropbox.com/s/qfovofhdldiwijn/I_Ref.mat?dl=0. Hope that your method achieved a good performance – user3051460 Aug 13 '15 at 19:25
  • @user3051460 - I'll verify the quality later tonight. Can't do that currently. – rayryeng Aug 13 '15 at 19:26
  • Ok. See you soon. Thanks – user3051460 Aug 13 '15 at 19:26
  • Very nice!! this is a good answer! What about Total variation denoising? – Ander Biguri Aug 14 '15 at 09:40
  • @AnderBiguri honestly I haven't tried TV because I couldn't find any ready made implementations to test. Guided filtering was available for a quick test. Would TV also work better here? – rayryeng Aug 14 '15 at 12:53
  • @rayryeng actually you are right, no Matlab inbuilt TV. I think TV will be great here. I might try some and if it works ill post a secondary answer – Ander Biguri Aug 14 '15 at 12:57
  • 2
    @user3051460 - I think it's best if **you** make the comparison yourself between what I and what Ander wrote and you figure out for yourself what method is better. You're the best one to determine that, and getting us to do the comparison for you won't allow you to learn anything. A simple test could be to threshold the gradient images so that they're edge pixels, then do a SSD between both of the images. PSNR is also a good approach and you can look here on how to compute it: http://stackoverflow.com/questions/16264141/power-signal-noise-ratio-psnr-of-colored-jpeg-image/16265510#16265510 – rayryeng Aug 14 '15 at 16:34
  • @rayryeng: I compared it. It is totally outperform than my method. Currently, I want to make the formula of Sobel edge (in mathematic) that looks like gaussian formula g=1/(1+β∇ (I*G)^2). Could you suggest to me some reference or the formula for above your implementation of sobel edge detection? I tried to describe your code max(Gmag(:)) - Gmag as g=1/(1+β*Gmag) but they are different. The range of 'max(Gmag(:)) - Gmag' will be from 0 to max(Gmag(:)) , while range of g=1/(1+β*Gmag) from 0 to 1. But when I use max(Gmag(:)) - Gmag, I saw that it achieve more accurate than g=1/(1+β*Gmag) – user3051460 Aug 29 '15 at 06:38
  • That's a separate question IMHO. Please consider asking another question. – rayryeng Aug 29 '15 at 14:07
3

Just for the shake of adding another method to @rayryeng's quite complete and interesting answer, I will show you how to denoise with the well known Split-Bregman Total variation algorithm.

This algorithm forces the image to have the "less possible amount of grayscale levels"*. Therefore, it will denoise the image (as similar gary-levels will be converted to the same) but it will preserve edges.

Matlab does not have a TV implemented, but you can check this implementation.

Sample of use (the code is self explanatory hopefully)

N = 256; n = N^2;

% Read image;
g=double(imread('https://i.stack.imgur.com/ACRE8.png'));
%fill it with zeroes to make a NxN image
sz=size(g);
img=zeros(N);
img(1:size(g,1),1:size(g,2))=g;
g=img;

% the higher this parameter is, the stronger the denoising
mu = 6;

% denoise 
g_denoise_atv = SB_ATV(g,mu);
%prepare output
denoised=reshape(g_denoise_atv,N,N);
denoised=denoised(1:sz(1),1:sz(2));

% edges
[Gmag,~] = imgradient(denoised, 'sobel');

subplot(131); imshow(g(1:sz(1),1:sz(2)),[]);title('Original');
subplot(132); imshow(denoised,[]);title('Denoised');
subplot(133); imshow(max(Gmag(:)) - Gmag,[]);title('Edges');

enter image description here]

If you play with the mu parameter you can get very denoised (but image data lost) images or very little denoised (but image quality data more preserved);

mu=40

enter image description here

mu=1;

enter image description here

* This is a non-mathematical explanation of the method. For the purists, check L1 regularization techniques.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120