フィルターのクリア

Batch processing images from 2 folders and saving them to another folder

1 回表示 (過去 30 日間)
Aero Descerazes
Aero Descerazes 2022 年 2 月 12 日
編集済み: Image Analyst 2022 年 2 月 12 日
Hello, I have two folders, Folder A and Folder B with unit8 binary images of same corresponding file names.
The folder structure is as follows:
Folder A
Image 1.bmp
Image 2.bmp
Image 3.bmp
...
Folder B
Image 1.bmp
Image 2.bmp
Image 3.bmp
...
I want to perform a simple operation imsubtract between the same filenames in the two folders. For example, (Image 1 from Folder A) - (Image 1 from Folder B). Similary (Image 2 from Folder A) - (Image 2 from Folder B), and so on. I want to batch process these, and save it to a different folder (e.g. Folder C). How would I go about doing this?
I have 400 images in Folder A and 400 images in Folder B with the same corresponding filenames. I want to batch export calculated 400 files (in for e.g. Folder C). Any help is very appreciated.

採用された回答

Image Analyst
Image Analyst 2022 年 2 月 12 日
編集済み: Image Analyst 2022 年 2 月 12 日
Do you want floating point differences? Positive and negative values allowed? Or do you want the absolute difference of the subtraction, like you'd get with imabsdiff(). I'll show the later
foldera = 'C:/imagesa';
folderb = 'C:/imagesb';
folderc = 'C:/imagesc';
if ~isfolder(folderc)
mkdir(folderc);
end
fileListA = dir(fullfile(foldera, '*.bmp'))
fileListB = dir(fullfile(folderb, '*.bmp'))
for k = 1 : length(fileListB)
% Build file names.
fileNameA = fullfile(foldera, fileListA(k).name);
fileNameB = fullfile(folderb, fileListB(k).name);
% Read them in.
imageA = imread(fileNameA);
imageB = imread(fileNameB);
% Compute difference
diffImage = imabsdiff(imageA, imageB);
imshow(diffImage, []);
drawnow;
% Write out result to result folder: same base file name, different folder.
fileNameC = fullfile(folderc, fileListA(k).name);
imwrite(diffImage, fileNameC);
end
  2 件のコメント
Aero Descerazes
Aero Descerazes 2022 年 2 月 12 日
編集済み: Aero Descerazes 2022 年 2 月 12 日
@Image Analyst Thanks for the response. Absolute values are fine. On line 11, it gave me an error: Unrecognized field name "Name". How do I fix this? I need the exported filename same as the input images.
Image Analyst
Image Analyst 2022 年 2 月 12 日
Sorry. It should be lower case .name.

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

その他の回答 (0 件)

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by