function Samples = ExtractSamples(Input,DownFactor)

BlockHeight=size(Input,1);
BlockWidth=size(Input,2);
KernelLength=64;

SCount=0;
% figure
% hold on;

for i=1:BlockHeight % loop and scan line by line
    

      X=double(Input(i,:));
      
      %--------------------
    
      
      %----- Linterpolation by the factor of 4 for better resolution------------    
      ti=1/4:1/4:BlockWidth; % interpolation by 4
      Xi = interp1(1:BlockWidth,X(1:BlockWidth),ti,'spline'); %'linear'); 

      Y=diff(Xi);
      Y(size(Xi,2))=0;
      Y=smooth(Y);
     
      %------------ Select Only Edges in the Center --------
     [YMax IMax]=max(abs(Y)/norm(Y));
     
     if and(IMax>4*2,IMax<4*(BlockWidth-2));

 
       SCount=SCount+1;
      %----- To crop and center it --------
      TmpVector=zeros(1,319);
      TmpVector(100:100+max(size(Y)-1))=Y;
      Y=ExtractKernel(TmpVector,KernelLength);
      
     if nnz(Y)>0
      if mean(Y)<0
      TmpSamples(SCount,:)=-Y/norm(Y);
      else
       TmpSamples(SCount,:)=Y/norm(Y);  
      end
     end
     %----------------------------
end
     %-------------------------------
end

 if norm(SCount)>DownFactor %--- at least one sample
Samples=TmpSamples';
%----------- Select only some samples by downsampling
Samples = downsample(Samples',DownFactor)';
 else
Samples=[];  
 end


return
