function p = splitimage(input,z,w,scale,sigma)
%
% p = splitimage(input,z,w,scale,sigma)
%
% function to compute the compute class probalilities
% try to segment the image into k different regions
%
%------------------input-------------------------------------
%
% input     \to  the input image
% z         \to  the training set
% w         \to  weights
% scale     \to  scale from the kernel function
% sigma     \to  parameter for the kernel

%   Authors:  Jun Li, 2009


x=input;
clear input

[d,n] =size(x);
nz = sum(z.^2);
n1 = floor(n/40);
p = [];
for i = 1:39
    x1 = x(:,((i-1)*n1+1):n1*i);
    nx1 = sum(x1.^2);
    [X1,Z1] = meshgrid(nx1,nz);
    clear nx1;
    dist1 = Z1-2*z'*x1+X1;
    K1=exp(-dist1/2/scale/sigma^2);
    K1 = [ones(1,n1); K1];
    p1=mlogistic(w,K1);
    p = [p p1];
end

x1 = x(:,(39*n1+1):n);
clear x
nx1 = sum(x1.^2);
[X1,Z1] = meshgrid(nx1,nz);
dist1 = Z1-2*z'*x1+X1;
K1=exp(-dist1/2/scale/sigma^2);
K1 = [ones(1,n-39*n1); K1];
p1=mlogistic(w,K1);
p = [p p1];

 