function p = pass1(xrow,xcol,Krow,Kcol)
% p = pass1(xrow,xcol,Krow,Kcol)
% Calculate likelihood of band centered at pixel
krow = round((Krow-1)/2);
kcol = round((Kcol-1)/2);
[m n] = size(xrow);
diam = sqrt((krow*krow)+(kcol*kcol));
p = zeros(m,n);
for ii = 1+krow:m-krow
  for jj = 1+kcol:n-kcol
    p(ii,jj) = 0.0;
    if xrow(ii,jj)+xcol(ii,jj) > 0
      rowct = 0; colct = 0;
      rimean = 0; rjmean = 0; cimean = 0; cjmean = 0;
      for i2 = ii-krow:ii+krow
        for j2 = jj-kcol:jj+kcol
          if xrow(i2,j2) > 0
            rowct = rowct+1;
            rimean = rimean+i2; rjmean = rjmean+j2;
          end
          if xcol(i2,j2) > 0
            colct = colct+1;
            cimean = cimean+i2; cjmean = cjmean+j2;
          end
        end
      end
      if rowct > 0
        rimean = rimean/rowct; rjmean = rjmean/rowct;
        dirow = ii-rimean; djrow = jj-rjmean;
      else 
        dirow = krow; djrow = kcol;
      end
      if colct > 0
        cimean = cimean/colct; cjmean = cjmean/colct;
        dicol = ii-cimean; djcol = jj-cjmean;
      else
        dicol = krow;
        djcol = kcol;
      end
      prow = min(rowct,Krow)/Krow;
      pcol = min(colct,Kcol)/Kcol;
      dr = sqrt((dirow*dirow)+(djrow*djrow));
      dc = sqrt((dicol*dicol)+(djcol*djcol));
      prcen = 1.0 - dr/diam;
      pccen = 1.0 - dc/diam;
      p(ii,jj) = (prow+pcol+prcen+pccen)/4.0;
    end
  end
end
