function [A, D] = BuildGraph(data, num_rows, num_cols)
% build graph on image for conditional random fields
% written by Jimei Yang @UCM, Oct 2011

% build the adjacent matrix A
x = 1:num_cols;
y = 1:num_rows;
[gridx, gridy] = meshgrid(x,y);
coord = [gridx(:)';gridy(:)'];
A = EuDist2(coord');
A(A>1) = 0;

% build the data dependent labeling edge matrix
D = EuDist2(data',[], 0);
% K = S'*S;