Write a function to add "randn" Gaussian noise to an specific percentage of images inside imageData store in matlab
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
0 Kommentare
Antworten (1)
Nitin Kapgate
am 6 Aug. 2020
Bearbeitet: Nitin Kapgate
am 6 Aug. 2020
Hi Mohamed,
I can understand that you want to add noise to a percentage of images in an ImageDataStore which are chosen at random.
Here is a demo code which will help you to solve your problem.
% Load images from a folder as ImageDataStore objects
imds = imageDatastore('C:\Users\XYZ\MyProject'); % Assuming your images are in “MyProject” folder
percentImages = 0.2; % Fraction of Images you want to add Noise
numTotalImg = numel(imds.Files) % Total number of Images in the Folder
numNoisyImg = round(percentImages * numTotalImg) % Number of images you want to add the Noise
selectedNoisyImages = randperm(numTotalImg,numNoisyImg); % Generate random indices of images to which noise is to be added
for k = 1:numNoisyImg
fileName = imds.Files{selectedNoisyImages(k)} % read the filename of the image with random index, to add noise
I = imread(fileName); % Read the image using imread function
% Insert Code to add noise to the image I here
% You may use "randn" or "imnoise" function to add the noise of your choice
% If needed, write back noisy image to a different folder.
end
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!