title: Sobel Edge detection – matlab
body: <p>hello as part of my Homework. i need to calculate and display the edge magnitude image and the 
  edge direction image of image balls1.tif, using Sobel Edge detection.</p>
  
  <p>Do not use matlab's edge function. You may use conv2.
  Display a binary edge image (1 edge pixel, 0 no edge) of strong edge pixels (above a threshold).
  Determine a threshold that eliminates the ball shadows.</p>
  
  <p>here is my main.m<br></p>
  
  <pre><code>addpath(fullfile(pwd,'TOOLBOX'));
  addpath(fullfile(pwd,'images'));
  
  %Sobel Edge Detection 
  Image = readImage('balls1.tif');
  showImage(Image);
  message = sprintf('Sobel Edge Detection');
  sobelEdgeDetection(Image);
  uiwait(msgbox(message,'Done', 'help'));
  close all
  </code></pre>
  
  <p>here is my SobeEdgeDetection.m </p>
  
  <pre><code>function [ output_args ] = SobelEdgeDetection( Image )
  
  maskX = [-1 0 1 ; -2 0 2; -1 0 1];
  maskY = [-1 -2 -1 ; 0 0 0 ; 1 2 1] ;
  
  resX = conv2(Image, maskX);
  resY = conv2(Image, maskY);
  
  magnitude = sqrt(resX.^2 + resY.^2);
  direction = atan(resY/resX);
  thresh = magnitude &lt; 101;
  magnitude(thresh) = 0;
  showImage(magnitude);
  
  end
  </code></pre>
  
  <p>my questions are:<br>
  1. i what is the direction used for ? and how can i display it? <br>
  2. is there a better way to get a threshold to eliminate the ball shadows. i used trial and error....</p>
  
  <p><img src="https://i.stack.imgur.com/RDYEM.jpg" alt="enter image description here"></p>
  
  <p>these are my result as far as showing the magnitude:</p>
  
  <p><img src="https://i.stack.imgur.com/bXWq8.jpg" alt="enter image description here"></p>