function im_out = skeniraj (net,im)

close all

SCAN_FOLDER = 'skeniraj\';
UT_FOLDER = 'skeniraj\ispod-praga\';
PREDLOZAK1 = 'predlozak1.png';      
PREDLOZAK2 = 'predlozak2.png';      
Threshold = 0.4;

warning off;
nntwarn off;
delete ([UT_FOLDER,'*.*']);
delete ([SCAN_FOLDER,'*.*']);
mkdir (UT_FOLDER);
mkdir (SCAN_FOLDER);

[m n]=size(im);

C1 = premnmx(double(im));
C2 = premnmx(double(imread (PREDLOZAK1)));
C3 = premnmx(double(imread (PREDLOZAK1)));
Corr_1 = double(conv2 (C1,C2,'same'));
Corr_2 = double(conv2 (C1,C3,'same'));
Cell.state = int8(imregionalmax(Corr_1) | imregionalmax(Corr_2));
Cell.state(1:13,:)=-1;
Cell.state(end-13:end,:)=-1;
Cell.state(:,1:9)=-1;
Cell.state(:,end-9:end)=-1;
Cell.net = ones(m,n)*-1;
figure;imshow (im);

    [i j] = find(Cell.state==1);
    for k = 1:size(i)
        imcut{k} = im(i(k)-13:i(k)+13,j(k)-9:j(k)+8);  
    end

    response = sim(net,seq2mat(imcut));
    for k = 1:size(i)
    Cell.net(i(k),j(k)) = response(k);
    end
                 
    if Cell.net(i,j) > Threshold
        Cell.state(i-1:i+1,j-1:j+1)=1;
    %elseif Cell.net(i,j) > 0.95
        %Cell.state(i-13:i+13,j-9:j+9)=-1;
    end        

hold off
xy_ = Cell.net > Threshold;
xy_ = imregionalmax(xy_);
xy_ = imdilate (xy_,strel('disk',2,4));
[LabelMatrix,nLabel] = bwlabeln(xy_,4);
CentroidMatrix = regionprops(LabelMatrix,'centroid');
xy_ = zeros(m,n);
for i = 1:nLabel
    xy_(fix(CentroidMatrix(i).Centroid(2)),...
           fix(CentroidMatrix(i).Centroid(1))) = 1;
end
xy_ = okvir(xy_,[27 18]);
im_out (:,:,1) = im;
im_out (:,:,2) = im;
im_out (:,:,3) = im;
for i = 1:m
    for j=1:n
        if xy_(i,j)==1
            im_out (i,j,1)=0;
            im_out (i,j,2)=255;
            im_out (i,j,3)=0;            
        end
    end
end

