Read, process and write image dataset

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 个评论

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.
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.
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.

请先登录,再进行评论。

 采纳的回答

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 个评论

Thank you for your reply, what is that filesep?
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)
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.
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.

请先登录,再进行评论。

更多回答(1 个)

Rahil
Rahil 2025-12-13
编辑:Rahil 2025-12-13
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

类别

帮助中心File Exchange 中查找有关 Data Import and Analysis 的更多信息

产品

版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by