function [edgemap,tetamap] = prewitt(myimg,thresh)
%T = [];
%A = [];
%for i=-2:2
%    for j=-2:2
%        T = [T;1 i j];        
%    end
%end
%syms a1,  a2,  a3,  a4,  a5,  a6,  a7,  a8,  a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25;
%A = [  a1,  a2,  a3,  a4,  a5,  a6,  a7,  a8,  a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25];
%c = ones(25,1);
%p = inv(T'*T)*T'*transpose(A);
prewit = [ -1 0 1; -1 0 1;-1 0 1;];
%[myimg,map] = imread(fname,'gif');
%myimg = ind2gray(myimg,map);
%colormap(gray);
%image(myimg);
padarray(myimg,[2,2]);
myimg=double(myimg);
ximg = conv2(myimg,prewit,'valid');
yimg = conv2(myimg,prewit','valid');
teta = yimg./ximg;
tetaimg = atan2(yimg,ximg);
tetaimg = reshape(tetaimg,size(yimg));
newimg =sqrt(ximg.^2+yimg.^2);
magimg=newimg/max(max(newimg));
colormap(gray);
%image(newimg);
%imview(magimg);
img = [];
i=0;
for row = newimg
    for index= 1:size(row)
        if(row(index)>thresh) 
            row(index)=1;
        else
            row(index)=0;
        end
    end
    img = [img row];
end
%img = imagesc(img);
%img
%imview(img);
%imwrite(magimg,'1-mag.jpg','jpeg');
%imwrite(img,'1-edge.jpg','jpeg');
%imview(img);
edgemap = img;
tetamap = tetaimg;