function EDGED=matlabsobel(MATRIX)

% Edge enhancement using the Sobel method.
%
% EXAMPLES:
%
% >> matlabsobel('cell.jpg')
%    where cell.jpg is the cellular pattern image
% OR
% >> matlabsobel(MATRIX)
%    where MATRIX is the double-type matrix of
%    the cellular pattern image, i.e. MATRIX=double(imread('cell.jpg')).
%
% >> EDGED=matlabsobel(...) returns as EDGED the matrix of the 
% enhanced edge image.


if isstr(MATRIX)
   MATRIX=double(imread(MATRIX)); % Turns the image into a matrix
end
% The previous loop allows us to input the image either as a function argument
% (then CELLIMAGE is a string, for instance cell.jpg),
% or the image matrix (then CELLIMAGE is a matrix).

[EDGED,t]=edge(MATRIX,'sobel'); % First try: Matlab selects its own threshold.
EDGED=grayscale(double(EDGED));
figure;colormap(gray);imshow(EDGED);title(sprintf('Matlabsobel -- Enhanced edges with a threshold of: %d',t));axis on;

m=menu('What would you like to do now?','Change threshold','Quit or return to main menu');

while m~=2
   sprintf(' Previous used threshold: %d',t)
   t=input(' Enter new threshold: ');
   EDGED=grayscale(double(edge(MATRIX,'sobel',t)));
   figure;colormap(gray);imshow(EDGED);title(sprintf('Matlabsobel -- Enhanced edges with a threshold of: %d',t));axis on;
   
   m=menu('What would you like to do now?','Change threshold','Quit or return to main menu');
   
end

return
