Denoise Image with Gaussian Noise Using MATLAB / Octave
You're trying to solve what's called Perona Malik Non Linear Diffusion Problem (Sometimes people call it, by mistake, Anisotropic Diffusion).

Anyhow, the simplest code for that is Anisotropic Diffusion (Perona &amp; Malik) on The MATLAB File Exchange.

There is a more advanced (Anisotropic for real) algorithm in Fast Anisotropic Curvature Preserving Smoothing (Also on the File Exchange - Fast Anisotropic Curvature Preserving Smoothing).

Enjoy...