Hello, I have image dataset containing 5000 images. I enhanced the one image from this dataset in the matlab my code is working good and i got good result. Now i need help in processing this all 5000 images using my filter code and have to store that processed images in my laptop local folder. How to read, process and write 5000 images in one go. can anybody know how to do that?

5 Kommentare

You don't do it in one go: you use a loop.
doc dir
doc for
doc parfor %if you have the parallel computing toolbox
Hello Rik thank you for your reply, actually i processed the 5000 images with my filter, its working great, now i need help in to store that processed 5000 images to my local machine(laptop). all images are of size 256x256 and png format.
Rik
Rik am 30 Jul. 2021
What is your question exactly? You have a pipeline that works for 1 image, so what is exactly the problem in getting it to work for a list of files?
I need help in storing my processed 5000 images to my laptop thats it bro.
Rik
Rik am 30 Jul. 2021
What is your question? Weren't you already writing the result to local storage? How does your current pipeline look? It should start with a way to load an image, and it should end with writing that image to some storage. How are you doing that last step?
Bro.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

KSSV
KSSV am 30 Jul. 2021

0 Stimmen

infolder = '' % give the path of the folder where your images are present
outfolder = '' % give the path of the folder where you want to save images
imgFiles = dir([infolder,filesep,'\*.png']) ; % give extension of your images
N = length(imgFiles) ; % total images in the foder
for i = 1:N
thisFile = [infolder,filesep,imgFiles(i).name] ; % each image file
[filepath,name,ext] = fileparts(thisFile) ; % get name of the image file and extension
outFile = [outfolder,filesep,[name,ext]] ; % write image file on this name here
I = imread(thisFile) ; % read image into
% do what you want on I
imwrite(I,outFile) ; % write the image in the said folder on the name
end

7 Kommentare

Thank you for your reply, what is that filesep?
filesep
ans = '/'
It worked thank you
One styllistic suggestion I have when using filesep, for example
[infolder,filesep,imgFiles(i).name]
is to write it instead with fullfile
fullfile(infolder,imgFiles(i).name)
Aravind Prabhu Gopala Krishnan
Bearbeitet: KSSV am 30 Jul. 2021
path = 'C:\Users\91894\Desktop\matlab\Dataset\images_001\images';
outfolder = 'C:\Users\91894\Desktop\matlab\Dataset\images_001\processed image';
img = imageDatastore(path,'IncludeSubfolders',1,'LabelSource','foldernames');
T = countEachLabel(img);
N = length(img.Files);
% i = readimage(img, 3000);
% imshow(i);
refback = zeros(25, 25);
for i = 1:N
data = readimage(img,N);
J = imresize(data,[256 256]);
for f = 1:4
SpatDog = fspecial('gaussian',25,0.732) - fspecial('gaussian',25,0.785);
FreqDog = fftshift(fft2(fftshift(SpatDog)));
Y = abs(FreqDog);
refback = refback + im2double(Y);
end
refback = (1/4) * refback;
Y = fftshift(ifft2(fftshift(refback)));
conv = conv2(Y,J);
end
This is my code, ur code format is not fiiting for my project. Can you please tell me how to store my processed image, its in the variable name conv, i need to write that images in my local folder, thats all. I cannot process the filter with your code. i attacked my workspace too. In that am having my processed image in conv 280x280, i need to store that.
KSSV
KSSV am 30 Jul. 2021
Your code format is not fitting? Where did you try to fit? Show the complete code which you have tried and didnt let you fit.
KSSV thanks for your help bro it worked actually after that.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Rahil
Rahil am 13 Dez. 2025
Bearbeitet: Rahil am 13 Dez. 2025

0 Stimmen

Updated version of code with example implementation
infolder = ''; %path to input folder
outfolder = ''; %path to output folder
if ~exist(outfolder, 'dir')
mkdir(outfolder);
end
%replace image extension as required
imgFiles = dir(fullfile(infolder, '*.tiff'));
N = length(imgFiles);
for i = 1:N
thisFile = fullfile(infolder, imgFiles(i).name);
[~, name, ext] = fileparts(thisFile);
outFile = fullfile(outfolder, [name ext]);
%To read the file
I = imread(thisFile);
%Do your operation below
if isa(I,'uint16')
I = im2double(I);
I = imnoise(I,'salt & pepper',0.02);
I = im2uint16(I);
else
I = imnoise(I,'salt & pepper',0.02);
end
%------------------------
%Writes the file to folder
imwrite(I, outFile);
end

Kategorien

Mehr zu Data Import and Analysis finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by