Batch processing images from 2 folders and saving them to another folder
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Aero Descerazes
el 12 de Feb. de 2022
Editada: Image Analyst
el 12 de Feb. de 2022
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.
0 comentarios
Respuesta aceptada
Image Analyst
el 12 de Feb. de 2022
Editada: Image Analyst
el 12 de Feb. de 2022
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 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!