how to save multiple images in different folders using a loop?
2 次查看(过去 30 天)
显示 更早的评论
Hello everyone, I am new in image processing and I want help. I have a folder (dataset) that contains 1000 images and I want to insert noise 'salt & pepper' with different density noise (0.01,0.02 and 0.03) , I used this line to do this:
im = imread('C:\Users\SAMSUNG\Desktop\AHTD3A0002_Para1.tif');
J = imnoise(im,'salt & pepper',0.01);
Please help me to do this : I want to save the result in 3 folder ( data1 contains images after noise with d=0.01, data2 contains images after noise with d=0.02 and data3 contains images after noise with d=0.03).
any suggestation and thanks in advance
0 个评论
采纳的回答
parth pandya
2016-5-20
Try This Code:
% Creating 3 New Folders
StoreDrive = 'D:';
ImgLoadDrive = 'C:\Users\SAMSUNG\Desktop\AHTD3A';
d = [ 0.01 0.02 0.03 ];
FolderNames = {'data1','data2','data3'};
for i=1:3
% FolderNames(i) = sprintf('data%01d',i);
Folder = fullfile(StoreDrive,FolderNames{i});
mkdir(Folder);
end
for i=1:1000
%we will read image once apply salt and pepper 3 times
%and then store images in different folder
ImgName = sprintf('%s%04d_para1.tif',ImgLoadDrive,i);
im = imread(ImgName);
for k=1:3
J = imnoise(im,'salt & pepper',d(k));
ImgStoreName = sprintf('%s_%04d.tif',FolderNames{k},k);
ImgStoreName = fullfile(StoreDrive,FolderNames{k},ImgStoreName);
imwrite(J,ImgStoreName);
end
end
Here I am creating 3 folders data1,data2 & data3 in D: drive.
Also I a assuming that your images are in this format:
AHTD3A0001_Para1.tif, AHTD3A0002_Para1.tif, AHTD3A0003_Para1.tif, AHTD3A0004_Para1.tif...
Hope this will help.
更多回答(1 个)
Tajinder Pal singh
2020-2-16
can you please help me in the follwoing
if in the same way as above i want to save the different images (in a loop around 1000 images) result in different folders(1000 in no.) results should not be overalpped
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!