function [model] = defineModel(dx,dy,model,quantVal) %Build a 2D Gradient histogram %Scale image between 0 and 255 sgradX = scale(dx,[0 255]); sgradY = scale(dy,[0 255]); %Quantize image qgradX = reduceGrad(sgradX,quantVal); qgradY = reduceGrad(sgradY,quantVal); model.qgradX = uint8(qgradX/quantVal + 1); model.qgradY = uint8(qgradY/quantVal + 1); sizeRegX = size(qgradX); sizeRegY = size(qgradY); maxheight = min([sizeRegX(1) sizeRegX(2)]); maxwidth = min([sizeRegX(2) sizeRegY(2)]); height = model.h(2)*2; width = model.h(1)*2; startX = model.center(1)-model.h(1); startY = model.center(2)-model.h(2); if(startX<1) startX = 1; end if(startY<1) startY=1; end index = uint8(256/quantVal + 1); model.gradTable(index,index) = double(0); model.modelDist(index,index) = double(0); CM1=0; %count gradient values for y = startY:startY+height-1 for x = startX:startX+width-1 indexX = x; indexY = y; if(x>=maxwidth) indexX = maxwidth; end if(y>=maxheight) indexY = maxheight; end if(x < 1) indexX=1; end if(y < 1) indexY=1; end diffX = model.qgradX(indexY,indexX); diffY = model.qgradY(indexY,indexX); normDist = (model.center-[x y])./model.h; kresult = epanech(normDist,1); CM1 = CM1+kresult; model.modelDist(diffX,diffY) = model.modelDist(diffX,diffY) + kresult; model.gradTable(diffX,diffY) = model.gradTable(diffX,diffY) + 1; end end model.C = 1/CM1; model.modelDist = model.modelDist*model.C; sum(sum(model.modelDist)); function [reduced] = reduceGrad(grad,quantVal); reduced = double(grad); reduced = quant(reduced,quantVal);