Adding high density salt and pepper noise to an image
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am taking 'cameraman.tif' as my input image.
How can I add high density salt and pepper noise to it so that if I place 3X3 window over it and scan for uncorrupted pixels in it the uncorrupted pixels will come out to be 3?
Please provide matlab code for this
1 Kommentar
Roaa Mohammed
am 3 Dez. 2019
clc; img = imread('cameraman.tif'); na = imnoise(img,'salt & pepper',0.02); black=3; white=253; nb = img; Rmatrix = randint(size(img,1),size(img,2),[0,255]); nb(Rmatrix <= black) = 0; nb(Rmatrix >= white) = 255; subplot 131;imshow(img),title('ORIGINAL IMAGE'); subplot 132;imshow(na),title('NOISE USING FUNCTION'); subplot 133;imshow(nb),title('NOISE WITHOUT USING FUNCTION');
Antworten (1)
Jaimin
am 3 Jan. 2025
To add high-density salt-and-pepper noise to an image such that only 3 uncorrupted pixels remain in any 3x3 window, you will need to carefully select the noise density. The salt-and-pepper noise will randomly turn some pixels to either 0 (pepper) or 255 (salt).
Kindly refer following code snippet for better understanding.
img = imread('cameraman.tif');
img = im2double(img);
windowSize = 3;
% Calculate the total number of pixels in a 3x3 window
totalPixelsInWindow = windowSize^2;
% Define the number of uncorrupted pixels desired
uncorruptedPixels = 3;
% Noise density is the proportion of corrupted pixels
noiseDensity = (totalPixelsInWindow - uncorruptedPixels) / totalPixelsInWindow;
noisyImg = imnoise(img, 'salt & pepper', noiseDensity);
noisyImg = im2uint8(noisyImg);
For more information kindly refer to following MathWorks documentation.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!