Adding Noise To A Folder OF Images in A Loop
Show older comments
Good day all,
I am trying to understand a FOR LOOP to read all of the images in a specific folder, ADD NOISE TO The Folder OF Images at once and then Write the noise images to another specific folder,
I read the matlab documentation to help my own self but I am stuck at the sprint f statement and cannot move onward
question:
- the sprintf s%glow%d.jpg should output glow1.jpg?
- some how the common g is being taken for %g function and output low1.jpg??!!!!
- required some understanding why this outputs 1 noise file rather than 53 different noise images?
my code: Please Help!
D = '/Users/mmgp/Documents/MATLAB/FTruth53/FTruth53Gnoise5/'
S = dir(fullfile(D,'*.jpg'));
for k = 1: numel(S)
F = fullfile(D,S(k).name);
I = imread(F);
imshow(I);
S(k).data = I;
end
imname = dir(fullfile(D, sprintf('*/*',k)));
numel(imname)
% Assume only the first image is relevant (just for example purpose).
imname = imname(1).name;
for j = 1:length(F)
%apply the noise
J = imnoise(I,'salt & pepper',noise(1));
%save image in the right folder
imwrite(J, fullfile('/Users/mmgp/Documents/MATLAB/FTruth53/FTruth53Gnoise5/WithNoise/data1', sprintf('gun%d.jpg', j, imname)));
end
2 Comments
Rik
on 27 May 2020
Have you read the documentation for sprintf? What part didn't you understand?
By now someone must have mentioned you should be using break points if you want to understand what your code is doing. Did you do that?
Accepted Answer
More Answers (0)
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!