使用滑动窗口技术匹配两个直方图

时间:2016-10-31 13:36:52

标签: matlab

这是我的代码包含两部分:一部分用于输入图像&另一个用于制作窗口并显示所有窗口......

如何使用此代码匹配直方图。

%% Input image section
[fname path]=uigetfile('*.jpg','select an image');
fname=strcat(path,fname);
image=imread(fname);
image=imresize(image,[42 42]);

%% Display main image
figure;
subplot(4,3,1);
imshow(image);
title('Normal Pic');

%% Making a window & displaying the windows
windowWidth = 40;
windowHeight = 40;
for j = 1:imageHeight - windowHeight +1
for i = 1:imageWidth - windowWidth + 1
    window = image(j:j + windowHeight - 1, i:i + windowWidth - 1, :);
    subplot(4,3,1+(j-1)*3+i);
    imshow(window);
    title('Window');

end

end

1 个答案:

答案 0 :(得分:1)

您已成功创建窗口。所以,让我们说你的第二张图片叫im

我只是分享一个伪代码。

% RGB to HSV conversion
im_hsv = rgb2hsv(im);
image_hsv = rgb2hsv(image);

% Histogram calculation
im_hist = imhist(im_hsv(:,:,1));

% Your double for loop goes here
for for
    % Window is dynamically changing, so we need to calculate the histogram in loop 
    window_hist = imhist(window(:,:,1));

    % Calculate pairwise distance 
    D = pdist(window_hist, im_hist);

    % Your program logic goes here with D 
end
end

看看pdist()' this sites。您可以指定要使用的指标。另外,我喜欢关于直方图比较的OpenCV documentation