Hi, may i know how to create a loop in this code for image subtraction? X is the reference image and variable in Y , I have 10 images in the folder
1 view (last 30 days)
Show older comments
clc
clear
close all
warning off;
x=imread('reference.png');
y=imread('3.png');
Image=x-y;
imshow(image);
title('difference of the image compare to reference');
0 Comments
Answers (2)
Rik
on 23 Jan 2022
Use a for loop.
You can use the sprintf function to generate the file name based on the iteration number, and you can use subplot to create a grid of axes.
Note that you should probably cast your images to double prior to the subtraction, as images tend to be uint8 and therefore don't support negative numbers.
0 Comments
yanqi liu
on 24 Jan 2022
Edited: yanqi liu
on 25 Jan 2022
% X is the reference image and variable in Y , I have 10 images in the folder
x=im2double(imread('reference.png'));
for i = 1 : 10
y = im2double(imread([ num2str(i) '.png'] ));
Image=x-y;
figure(i);
imshow(Image, []);
title('difference of the image compare to reference');
end
4 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!