## 源码简介

function H=HistConnect(X,B,R)
% This Function HistConnect will make a smooth histogram for a signal
% or image consisting of a few samples. The function assumes correlation
% between the samples, and implicitly generates new linear-interpolated
% samples between the orignal samples. Thus makes the assumption of
% continuity between samples and low-frequency signal.
%
% (If your samples are spatial uncorrelated, use X=sort(X) before using
%  this function)
%
%  H=HistConnect(X,B,R)
%
%  X : A 1D vector or 2D matrix (image) with sample values
%  B : The number of histogram bins (default 256)
%  R : A vector [1 x 2], with the min and max histogram boundary,
%                       (default R=getrangefromclass(X))
%
% Example how it works,
%  - You want 3 bins
%  - Measured samples [0 0.3 0.7 1]
%  - Histogram edges [0 1/3] [1/3 2/3] [2/3 1];
%  A normal histogram function will return:
%   H= [2 0 2]
%
%  This histogram function makes histogram-blocks between two
%  values in the sample vector
%    sample value 0   connect with 0.3 : [1.33 0.00  0.00]
%    sample value 0.3 connect with 0.7 : [0.11 1.11  0.11]
%    sample value 0.7 connect with 1.0 : [0.00 0.00  1.33]
%                                      ---------------------
%                                      H = [1.44 1.11 1.44]
%
%
%
%  Example, Signal:
%
%     XN=sin(2*pi*(1/2000)*(1:2000))/2+0.5;
%     XS=sin(2*pi*(1/20)*(1:20))/2+0.5;
%    figure,
%     subplot(3,2,1), plot(XN,'r.'); title('High Sampled Sine');
%     subplot(3,2,2), plot(XS,'r.'); title('Low Sampled Sine');
%     subplot(3,2,3), plot(hist(XN,256)); title('Normal Hist, High Sampled');
%     subplot(3,2,4), plot(hist(XS,256)); title('Normal Hist, Low Sampled');
%     subplot(3,2,5), plot(HistConnect(XN,256),'g'); title('Connect Hist, High Sampled');
%     subplot(3,2,6), plot(HistConnect(XS,256),'g'); title('Connect Hist, Low Sampled');
%
%  Example, Image :
%     XS = XN(1:15:end,1:15:end);
%    figure,
%     subplot(3,2,1), imshow(XN); title('High Sampled Image');
%     subplot(3,2,2), imshow(XS); title('Low Sampled Image');
%     subplot(3,2,3), plot(imhist(XN)); title('Normal Hist, High Sampled');
%     subplot(3,2,4), plot(imhist(XS)); title('Normal Hist, Low Sampled');
%     subplot(3,2,5), plot(HistConnect(XN,256),'g'); title('Connect Hist, High Sampled');
%     subplot(3,2,6), plot(HistConnect(XS,256),'g'); title('Connect Hist, Low Sampled');
%
%
%  Function is written by D.Kroon University of Twente (February 2011)

if(ndims(X)>2),
error('HistConnect:inputdims','Only 1D or 2D input supported');
end

if(nargin<2), B=256; end
if(nargin<3), R=getrangefromclass(X); end

if((size(X,1)==1)||(size(X,2)==1))
% Vector Connecting Edges
if(length(X)==1)
E=[1 1];
else
i=(1:length(X)-1)';
E=[i i+1];
end
else
% Matrix Connecting Edges
ind=reshape(1:numel(X),size(X));
indx1=ind(1:end-1,:);
indx2=ind(2:end,:);
indy1=ind(:,1:end-1);
indy2=ind(:,2:end);
E1=indx1(:);indy1(:);
E2=indx2(:);indy2(:);
E=[E1 E2];
end

% Convert values to range [0..1]
X=double(X);
X=X-R(1);
X=X./(R(2)-R(1));

% Limit the Values to class boundary
X(X<0)=0; X(X>1)=1;

% Scale the values with the number of bins
X=X*B;

% Calculate the (linear interpolated) edge-histogram
H=edge_histogram(X(E),B);

% Sum of histogram is equal to number of connecting-edges,
% make it equal to the number of values.
H=H*(numel(X)/size(E,1));

function H=edge_histogram(V,B)
V=sort(V,2);
Vf=floor(V)+1; Vf(Vf>B)=B;
D=[-V(:,1) 1+V(:,2)]+[Vf(:,1) -Vf(:,2)];
H=zeros(size(V,1),B);
for i=1:size(V,1)
H(i,Vf(i,1)+1:Vf(i,2)-1)=1;
H(i,Vf(i,1))=H(i,Vf(i,1))+D(i,1);
H(i,Vf(i,2))=H(i,Vf(i,2))+D(i,2);
end
H=H./repmat(sum(H,2),[1 B]);
H=sum(H,1);

## 本站长期招聘程序代写高手，欢迎加入华南地区matlab团队

 想创业却没有经验的人 无论你是否有过网上开店的经验，都可以随时联系在线客服，建立自己独立的网站 想开网店却不知道如何入手 淘宝创业成本低而且风险小，如果想开淘宝店的朋友可以联系在线客服。 想兼职创业，却不擅长交际与服务的人 在家创业月入5000元。网站程序+百套群发工具+网赚资料+域名+空间+本站终身代理资格，这样你网赚的条件全具备了。每天3小时管理、推广、收钱。 缺乏能快速赢利型产品的人 导入多种最新流行营销软件+网赚教程，让入驻者轻松加盟、复制有效成交技巧、快速赚钱。
·上一源码：基于薄skel目录的骷髅
·下一源码：matlab跟踪移动对象

## 源码评论评论内容只代表网友观点，与本站立场无关！

评论摘要(共 0 条，得分 0 分，平均 0 分) 查看完整评论

## 浏览说明

* 本站所有源码全部公开，随时随地浏览!
* MATLAB软件如用于商业用途，请购买正版!
* 如果您发现下载链接错误，请点击报告错误谢谢！
* 站内提供的所有软件包含破解及注册码均是由网上搜集，若侵犯了你的版权利益，敬请来信通知我们!