l'image de fond

fr       en

Gray Level Image Processing

Change Detection

Method

The purpose is to show the changes between two images. The method is rather easy because it makes the difference between the two images for each pixel. The subtraction of two identical pixels give a null result (black) and two different pixels give a nonzero result.

Program

clear all; close all;

[filename, pathname] = uigetfile({'*.jpg;*.tif;*.PNG;*.gif;*.bmp','All Image Files';...
          '*.*','All Files' },'img1',...
          'C:\Work\myfile.jpg') % récuperation du chemin du fichier première image

img1 = imread(filename); % récuperation des données
if (length(size(img1))>2)% si l'image en niveau de gris est sur 3 composantes couleurs
    img1=img1(:,:,1);% on prend un seul plan
end
[filename, pathname] = uigetfile({'*.jpg;*.tif;*.PNG;*.gif;*.bmp','All Image Files';...
          '*.*','All Files' },'img2',...
          'C:\Work\myfile.jpg') % récuperation du chemin du fichier seconde image

img2 = imread(filename); % recuperation des données
if (length(size(img2))>2)% si l image en niveau de gris est sur 3 composantes couleurs
    img2=img2(:,:,1);% on prend un seul plan
end


k=8;
[ligne colonne]=size(img1);%taille de la matrice


image_result=uint8(zeros(ligne,colonne));
for i = 1: ligne
    for j = 1 : colonne
        if img1(i,j)>=img2(i,j)
            image_result(i,j)= img1(i,j)-img2(i,j);
        else
            image_result(i,j)= img2(i,j)-img1(i,j);
        end
    end
end
 % affichage
 figure(1)
 subplot(221)
 imshow(img1)
 subplot(222)
 imshow(img2)
 subplot(223)
 imshow(image_result)

Example


soustraction de deux images
Because we are in digital, we must be careful to overflow. If we substract a pixel p1 which is higher than p2, that works well. However, if p1 is smaller than p2 than the result will be a negative number. This gives a trouble because it will not be well represented compared to the original bits (big problem if the bytes are unsigned). Look at the problems caused.
mauvaise soustraction de deux images

Copyright © 2010-2014, all rights reserved, contact: operationpixel@free.fr