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 回表示 (過去 30 日間)
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');

回答 (2 件)

Rik
Rik 2022 年 1 月 23 日
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.

yanqi liu
yanqi liu 2022 年 1 月 24 日
編集済み: yanqi liu 2022 年 1 月 25 日
% 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 件のコメント
Rik
Rik 2022 年 1 月 24 日
I meant the clc; clear all; close all;.
I would not blindly repeat code the OP posted. If they really need to turn off all warnings, they will be able to put that line in their code again. Ritual inclusion of that code reinforces bad habits. People should be using functions to keep their workspace clean, use handles when dealing with graphics objects, and not forget semicolons. If you do those 3 things, clear (and clear all especially), close all, and clc are almost never required.
yanqi liu
yanqi liu 2022 年 1 月 25 日
yeah,thanks,i will notice it @Rik

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

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by