save new images in a folder

1 回表示 (過去 30 日間)
narges
narges 2020 年 1 月 25 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 25 日
Hi there,
I need to read several images from a folder (BigImage), split them into 4, and save the new images in another folder(Split).
here is my code, imwrite it will save only one new image, how ceate a loop to save all the new images?
N = 'C:\Users\BigImage';
S = dir(fullfile(N,'*.png'));
for k = 1:numel(S)
F = fullfile(N,S(k).name);
I = imread(F);
[r c p]= size(I);
A = I(1:r/2, 1:c/2, :);
B = I(1:r/2, c/2+1:c, :);
C = I(r/2+1:r, 1:c/2, :);
D = I(r/2+1:r, c/2+1:c, :);
cd 'C:\Users\split'
for ii = 1:k
imwrite( B, strcat ('part2', num2str(ii),'.png'));
end
end

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 1 月 25 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 25 日
#Do change as per requirement.
Images=dir('C:\input_path\folder_name\*.png'); % Folder with input Images
outDirectory='C:\out_put_path\out_folder_name\'; % Save Folder
for i=1:length(Images)
ImgName=strcat('C:\C:\input_path\folder_name\',Images(i).name);
In_image=imread(ImgName);
%% Do operation
%Save the image, say result_image
imwrite(result_image,strcat(outDirectory,Images(i).name));
end
  3 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 1 月 25 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 25 日
Consider all images in one folder, output folfer will automatically creates in the respective path
Images=dir('C:\Users\BigImage\*.png'); % Folder with input images
%.....................^^ Input Folder Name
outDirectory='C:\Users\Desktop\split' % Output folder will automatically creates
narges
narges 2020 年 1 月 25 日
Yes, Thanks a lot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by