```
% OTSU THRESHOLDING
% X=imread('cameraman.tif')
% a=ones(256,1)*[1:256];
% c2=double(X).*(a/2+50)+(1-double(X)).*a/2;
% c3=uint8(255*mat2gray(c2));
% IDX = otsu(c3,2); 
%----------------------------------------------------------
%
% function [IDX,sep] = otsu(I,n)

I = single(I);

    %% Convert to 256 levels
    I = I-min(I(:));
    I = round(I/max(I(:))*255);

    %% Probability distribution
    unI = sort((I));
    nbins = min(length(unI),256);

    [histo,pixval] = hist(I(:),256);

    P = histo/sum(histo);

    %% Zeroth- and first-order cumulative moments
    w = cumsum(P);
    mu = cumsum((1:nbins).*P);

    %% Maximal sigmaB^2 and Segmented image
    if n==2
        sigma2B =...
            (mu(end)*w(1:end-1)-mu(1:end-1)).^2./w(1:end-1)./(1-w(1:end-1));

        [maxsig,k] = max(sigma2B);
        k

```

This is the code i am using to find the Otsu threshold(2 class only). So after finding the optimal threshold ie k , How to compute the thresholded image?? 
how to change each image pixel value < k = 0 and >= k = 1 such that it creates a binary image?