function [ IDX,clustmap ] = makemapspatial( scoresmatrix,a,b,lims1,lims2)
global nrows rg
st=[];
[sobel_filt]=edge(rgb2gray(imfuse(reshape(scoresmatrix(:,a),nrows,[]),reshape(scoresmatrix(:,b),nrows,[]))),'sobel',st,'nothinning');
sobel_linear=reshape(sobel_filt,size(scoresmatrix,1),[]);
sobel2=(sobel_filt-1)*-1;
xmatrix=[scoresmatrix(:,a) scoresmatrix(:,b)];
xmatrix(repmat(sobel_linear,1,2)==1)=NaN;
IDX1=ones(size(scoresmatrix(:,a)));
IDX2=ones(size(scoresmatrix(:,b)));
for n=1:(size(lims1,2));
    IDX1(scoresmatrix(:,a)>lims1(n))=n+1;   
end
for n=1:(size(lims2,2));
    IDX2(scoresmatrix(:,b)>lims2(n))=n+1;   
end
IDX=ones(size(IDX1));
r=1;
for w=1:max(IDX1)
    for q=1:max(IDX2)
        IDX(IDX2==q & IDX1==w)=r;
        r=r+1;
    end
end
k=r-1;
clustmap=IDX;
clustmap=reshape(clustmap,nrows,[]);
rIDX=mat2gray(clustmap);

cmap=colourgen(IDX,k);
cmapr=cmap(:,1);
cmapg=cmap(:,2);
cmapr(sobel_linear==1)=0;
cmapg(sobel_linear==1)=0;
cmap(:,1:2)=[cmapr cmapg];

rg=zeros(256,3);
rg(:,1)=linspace(0,1,256);
rg(:,2)=linspace(1,0,256);

figure;
imshow(rIDX);
colormap(rg);
str = sprintf('Cluster Map, Scores (%d,%d); k = %d',a,b,k);
title(str);

clustmap(sobel_filt==1)=0;
rIDX=mat2gray(clustmap);
rIDX=imfuse(rIDX,sobel2,'blend');
figure;
imshow(rIDX);
colormap(hot);
str = sprintf('Sobel Exclusions, Scores (%d,%d); k = %d, Sobel Threshold = %f',a,b,k,st);
title(str);

figure;
scatter(scoresmatrix(1:100:end,a),scoresmatrix(1:100:end,b),10,cmap(1:100:end,:),'filled');
str = sprintf('Score %d',a);
xlabel(str);
str = sprintf('Score %d',b);
ylabel(str);
str = sprintf('Cluster Plot, Scores (%d,%d), k=%d',a,b,k);
title(str);
mapvars=[a,b,k,st];
putvar(sobel_filt,mapvars);
end