Adding Random valued impulse noise to an image

Version 1.0.0.0 (997 Bytes) by Sajid Khan
This function add random valued impulse noise of certain noise density and width
70 Downloads
Updated 3 Apr 2016

View License

function [ image_noisy ] = addRVIN( image_input, ND, noise_width )
%ADDRVIN adds Random valued impulse noise to an image
% image_input Input noise free image
% ND is noise density that ranges from 0 to 1
% noise_width is width of random valued impulse noise
[~,x] = imhist(image_input);
init_width = x(noise_width);
image_noisy = image_input;
Narr = rand(size(image_noisy));
p = ND/2;
% image_noisy = (image_input + p*rand(size(image_input)))/(1+p);
image_rand = rand(size(image_input));
range_init = init_width;
image_randInit = image_rand*range_init;
% image_noisy(Narr<ND/2) = (init_width + image_rand(Narr<ND/2));
image_noisy(Narr<ND/2) = (image_randInit(Narr<ND/2));
% image_noisy(Narr<ND/2) = (noise_width + p*rand(size(image_input)))/(1+p);
image_randFinal = image_rand*range_init+ x(end) - x(noise_width+1);
image_noisy((Narr>=ND/2)&(Narr<ND)) = image_randFinal((Narr>=ND/2)&(Narr<ND));
% figure, imhist(image_input)
% figure, imhist(image_noisy)

end

Cite As

Sajid Khan (2024). Adding Random valued impulse noise to an image (https://www.mathworks.com/matlabcentral/fileexchange/56324-adding-random-valued-impulse-noise-to-an-image), MATLAB Central File Exchange. Retrieved .

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0

Histogram added