كود لقراءة مجموعة صور مجلد:
هذا الكود يقرأ مجموعة من الصور داخل مجلد تقوم بتحديد مساره, ويمكنك تنفيذ أي دالة على هذه المجموعة من الصور وحفظ الصور في مجلد آخر تحدد مساره وبنفس الإسم الأصلي.
clear clc input_folder = 'D:\...'; % Enter name of folder from which you want to upload pictures with full path output_folder = 'D:\...'; % Enter name of folder from which you want to upload pictures with path except last folder filenames = dir(fullfile(input_folder, '*.jpg')); % read all images with specified extention, its jpg in our case total_images = numel(filenames); % count total number of photos present in that folder Outputs=total_images; dir=output_folder; for i = 1:total_images full_name= fullfile(input_folder, filenames(i).name); % it will specify images names with full path and extension our_images = imread(full_name); % Read images I = our_images; % ================(ضع ماذا تريد أن تفعل)=============== % I=rgb2gray(I); I1=histeq(I); % Hestegram Equalization I2=imresize(I1,[240 240]); %resize image % I2 = imresize(I1,0.4); % ====================================================== filename = filenames(i).name; fullname = fullfile(output_folder,'Put Last Folder Here',filename); imwrite(I2,fullname) % Write out to a JPEG file (img1.jpg, img2.jpg, etc.) end
يمكنك وضع أي دالة لتعديل الصور في المكان المشار إليه كــ (ضع ماذا تريد أن تفعل), مع العلم أن الصورة محفوظة في متغير (I).