File Exchange

image thumbnail


version (5.92 KB) by Tristan Ursell
Reduce image noise by measuring local pixel statistics and remapping intensities.


Updated 13 Dec 2016

View License

Tristan Ursell
Relative Noise Transform
(c) 2012 - 2016
Iin = the input image, of any numerical class.

sz = (3 < sz < min(size(Iin))) is the size of the filter block used to calculate means and variances. This value must be odd.

sigma (sigma > 0) is the weighting parameter that defines the standard
deviation relative to the filter block's standard deviation around which the center pixel will be Gaussian weighted. Setting sigma = 1 weights the current pixel using the STD of the current filter block. Lower values bring the current pixel closer to the mean, while high values are more tolerant of variations. As sigma -> Inf, Iout = Iin.

The field 'plot' will create an output plot comparing this transform to the original image, a Gaussian blur with STD = sz/2, and median filter with block size equal to sz. At first glance, this filter appears similar to a median transform, but it does a better job of preserving local intensity extrema. Comparison with the median filter requires the Image Processing Toolbox, but the rest of the script does not.

The field 'disk' or 'square' will choose between using a disk or square filter block shape, where sz is the disk diameter or square side length. The default is square.

The field 'custom' may be followed by a user-defined logical matrix or strel, e.g. relnoise(Iin,sz,sigma,'custom',strel('line',30,45)). In this case 'sz' will be unused.

Iout is the transformed output image.

Ivar is the variance of the pixel intensities in the filter block at every point in the image -- essentially the spatially varying variance of the image.

Imean is the mean smoothed image using the filter block, equivalent to a convolution averaging filter with the specified neighborhood.

see also: wiener2 filter2




title('What was removed from the original image.')
axis equal tight
box on

title('FFT of difference between original and filtered images.')
axis equal tight
box on

Comments and Ratings (8)

@Chayanon, the output image would be white in imwrite if you were saving it as the incorrect bit scale. Try something like:


I did that and it returned all white tiff file.

@Chayanon -- sounds like your issue is with imwrite. You should check the class of the input and output images before saving. Try: imwrite(double(Iout),'ch2DN.tiff')

How to save the output denoised image? Imwrite returns with error: (I am a novice)
>> imwrite(Iout,'ch2DN.tiff');
Error using writetif (line 92)
Writing single image data to a TIFF file is not supported with IMWRITE. Use
Tiff instead. Type "help Tiff" for more information.

Error in imwrite (line 472)
feval(fmt_s.write, data, map, filename, paramPairs{:});

>> imwrite(Iout,'ch2DN', Tiff);
Error using imwrite>parse_inputs (line 540)
Invalid input arguments.

Error in imwrite (line 418)
[data, map, filename, format, paramPairs] = parse_inputs(varargin{:});

@ Krishna, what exactly do you mean by "unknown scaling" -- the output image is the same size as the input image, so there's no scaling there, and the intensity values are not scaled, they are of course adjusted by the calculation itself. You can subtract the input from the output and verify that it removes (mostly) noise ... and hence there is no scaling.

I designed this filter, but it is something like a cross between an averaging and median filter.

If this clarified things for you, please consider re-rating this to 5 stars.

It is awesome! Worked very well for the first time without IPT and not knowing much about the algorithm in use. 2 additional things would help much better...a) the axes are being scaled to unknown values; would be better to restore the scaling of Iout vector to Iin, b) any literature references to help understand the basics of the algorithm. Thanks.

if you like this function, please consider rating it! (if you don't, please tell me why)


switched output to double.

support of arbitrary pixel neighborhoods, improved edge handling and normalization

improved edge pixel handling, fixed small bug

Improved how the algorithm handles regions of zero variance.

fixed typos

No longer requires the Image Processing Toolbox.

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux