Pairwise image subtraction from a folder
显示 更早的评论
Hi, I have a folder with 30 images (saved them as .mat file). I want to get the difference image and save them, therefore, my code should produce 15 images. I want (image1-image2), (image3-image4), (image5-image6), (image7-image8) and so on. The code I've written is attached below:
for j = 1:length(filenames_asl)
label_name = char(filenames_asl(j)); % filename_asl is the string array where the sequential filenames are saved
control_name = char(filenames_asl(j+1)); % Second image (filename)
label = load(strcat(foldername_asl, '/', label_name)).im1; % Loading the first image
control = load(strcat(foldername_asl, '/', control_name)).im1; % Loading the second image
asl_image = label - control; % Getting difference image
imagename_asl = fullfile(dir_asl, strcat(im_name_asl, '_', num2str(j), '.mat')); % Specifying name and location for saving the difference images
save(imagename_asl); %% Saving the difference image
j = j+2; % Increment of the loop index to skip the second image at the beginning of the next iteration
end
I have faced two problems:
- I'm getting 29 images running this code, I'm not sure why.
- I'm getting an error at the end of the loop saying 'Index must not exceed 30'.
Can anyone please help with this problem? Thanks in advance.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Images 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!