MATLAB: Hello… the problem is i have 4 images…i need to subtract an image 2 with image 1, image 3 with image 1 and image 4 with image 1…so how can i do this process in one loop

digital image processingfor loopimage processing

this is my code :
nextImage = {}; k = 1; for i = 0:3 nextImage{k} = imread(['a',num2str(i),'.jpg']); nextImage{k} = rgb2gray(nextImage{k}); figure; imshow(nextImage{k});
subtractImage{k} = imsubtract(double(['nextImage',num2str(j)]),(nextImage(0)));
figure;
imshow(subtractImage{k});
end

Best Answer

image_name = {'first' 'second' 'third' 'fourth'}; % give names with extension
I1 = imread(image_name{1}) ; % read first image
for i = 2:4 % loop for rest of images
I2 = imread(image_name{i}) ; % read i'th image
I12 = I2-I1 ; % substract
% do what you want
end
Related Question