【问题标题】:Match two histogram using sliding window technique使用滑动窗口技术匹配两个直方图
【发布时间】:2016-11-01 01:53:21
【问题描述】:

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

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

%% 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

【问题讨论】:

  • 你试过什么?这看起来像您要求为您编写代码!我希望这不是发生的事情
  • 我们在谈论什么类型的直方图? 2D (RGB HSV, ), 1D (Grayscale) 为什么要用滑动窗口来比较它们?您在查看小区域的直方图吗?
  • @cagatayodabasi 我想使用色调直方图。我想为每个窗口制作色调直方图,并将它们与我将从目标对象获得的另一个直方图相匹配。
  • @AnderBiguri 我想使用色调直方图。我想为每个窗口制作色调直方图,并将它们与我将从目标对象获得的另一个直方图相匹配。
  • 你想得到什么?为什么它不起作用?

标签: matlab


【解决方案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() 的documentation。您可以指定要使用的指标。另外,我喜欢OpenCV的documentation关于直方图比较。

【讨论】:

  • 非常感谢 :) 让我试试看。
猜你喜欢
  • 2014-06-07
  • 2019-01-23
  • 1970-01-01
  • 2018-07-23
  • 2012-10-15
  • 2015-01-02
  • 1970-01-01
  • 1970-01-01
  • 2021-09-08
相关资源
最近更新 更多