MATLAB - Image Edge Detection using Robert Operator from Scratch Last Updated : 28 Jul, 2023 Comments Improve Suggest changes Like Article Like Report Robert Operator: This gradient-based operator computes the sum of squares of the differences between diagonally adjacent pixels in an image through discrete differentiation. Then the gradient approximation is made. It uses the following 2 x 2 kernels or masks – \[M_{x}=\left[\begin{array}{ccc}1 & 0 \\ 0 & -1\end{array}\right] \quad M_{y}=\left[\begin{array}{ccc}0 & 1 \\ -1 & 0\end{array}\right]\] Approach: Step 1: Input - Read an image Step 2: Convert the true-color RGB image to the grayscale image Step 3: Convert the image to double Step 4: Pre-allocate the filtered_image matrix with zeros Step 5: Define Robert Operator Mask Step 6: Edge Detection Process (Compute Gradient approximation and magnitude of vector) Step 7: Display the filtered image Step 8: Thresholding on the filtered image Step 9: Display the edge-detected image Implementation in MATLAB: MATLAB % MATLAB Code | Robert Operator from Scratch % Read Input Image input_image = imread('[name of input image file].[file format]'); % Displaying Input Image input_image = uint8(input_image); figure, imshow(input_image); title('Input Image'); % Convert the truecolor RGB image to the grayscale image input_image = rgb2gray(input_image); % Convert the image to double input_image = double(input_image); % Pre-allocate the filtered_image matrix with zeros filtered_image = zeros(size(input_image)); % Robert Operator Mask Mx = [1 0; 0 -1]; My = [0 1; -1 0]; % Edge Detection Process % When i = 1 and j = 1, then filtered_image pixel % position will be filtered_image(1, 1) % The mask is of 2x2, so we need to traverse % to filtered_image(size(input_image, 1) - 1 %, size(input_image, 2) - 1) for i = 1:size(input_image, 1) - 1 for j = 1:size(input_image, 2) - 1 % Gradient approximations Gx = sum(sum(Mx.*input_image(i:i+1, j:j+1))); Gy = sum(sum(My.*input_image(i:i+1, j:j+1))); % Calculate magnitude of vector filtered_image(i, j) = sqrt(Gx.^2 + Gy.^2); end end % Displaying Filtered Image filtered_image = uint8(filtered_image); figure, imshow(filtered_image); title('Filtered Image'); % Define a threshold value thresholdValue = 100; % varies between [0 255] output_image = max(filtered_image, thresholdValue); output_image(output_image == round(thresholdValue)) = 0; % Displaying Output Image output_image = im2bw(output_image); figure, imshow(output_image); title('Edge Detected Image'); Input Image - Filtered Image: Edge Detected Image: Advantages: Detection of edges and orientation are very easy Diagonal direction points are preserved Limitations: Very sensitive to noise Not very accurate in edge detection Comment More infoAdvertise with us Next Article How To Detect Face in Image Processing Using MATLAB? G goodday451999 Follow Improve Article Tags : Software Engineering Image-Processing MATLAB Similar Reads MATLAB - Image Edge Detection using Prewitt Operator from Scratch Prewitt Operator: It is a gradient-based operator. It is one of the best ways to detect the orientation and magnitude of an image. It computes the gradient approximation of image intensity function for image edge detection. At the pixels of an image, the Prewitt operator produces either the normal t 3 min read MATLAB - Image Edge Detection using Sobel Operator from Scratch Sobel Operator: It is a discrete differentiation gradient-based operator. It computes the gradient approximation of image intensity function for image edge detection. At the pixels of an image, the Sobel operator produces either the normal to a vector or the corresponding gradient vector. It uses tw 3 min read Edge detection using first derivative operator in MATLAB An edge in an image is a significant local change in image intensity, usually associated with a discontinuity in image intensity or the first derivative of image intensity. The discontinuities in the intensity of the image can be stepped discontinuities, in which the intensity of the image changes f 3 min read Image Edge Detection Operators in Digital Image Processing In digital image processing edges are places where the brightness or color in an image changes a lot. These changes usually happen at borders of objects. Detecting edges helps us understand the shape, size and location of different parts in an image. Edge detection is used to recognize patterns, und 5 min read How To Detect Face in Image Processing Using MATLAB? MATLAB Â is a programming platform that is mainly used by engineers and scientists to analyze and design systems. Image processing is a process to perform some operations on an image to get an enhanced image or to extract some useful information from it. Each picture is stored as an array and each pi 5 min read Edge detection using Prewitt, Scharr and Sobel Operator The discontinuity in the image brightness is called an edge. Edge detection is the technique used to identify the regions in the image where the brightness of the image changes sharply. This sharp change in the intensity value is observed at the local minima or local maxima in the image histogram, u 4 min read Like