在MATLAB中比较两个或多个图像之间的像素

时间:2016-11-20 20:50:16

标签: matlab image-processing computer-vision

我正在尝试比较两个不同图像之间的像素。我已经在MATLAB中编写了我的脚本,但我似乎无法找到一种方法来存储类似的像素以及测试图像和图像文件夹中的像素之间的差异。有人可以帮我弄清楚如何最好地逐个像素地比较不同的图像吗?

这是我的代码:

clc; clear;

%initialize test image
test_img = imread('testImage.bmp');

% Locate Image directory
directory = dir('*.bmp');
files = {directory.name};

% initialize the similar and diiferent var
similar = {};
different = {};

% get the row and col sizes from the test image
[row, col] = size(test_img(:,:,1));

%loop through the images in a folder
for k=1:numel(files)
  for xAxis = 1 : row
    for yAxis = 1 : col
      %select each image
      im{k} = imread(files{k});

      %check the difference with the test image
      p{k} = im(:,k); %compose a 1X26 cell array to store all the images
      if isequal(p{1,k}{1,1}(xAxis,yAxis), test_img(xAxis,yAxis))
        similar = {xAxis, yAxis};
      else
        different = {xAxis, yAxis};
      end

      %figure;imshow(p{1,k}{1,1});

      %report the diference

      %store each difference in a vector
    end
  end
  disp(similar);
end

%look for the minimum vector

0 个答案:

没有答案