How to perform a thresholding operation on the gradient magnitude?

E
Eren · Feb 16, 2024 · 2K views
Question
This is the rules:   A simple edge detector using gradient magnitude   1. Compute gradient vector at each pixel by convolving image with horizontal and vertical derivative filters 2. Compute gradient magnitude at each pixel 3. If magnitude at a pixel exceeds a threshold, report a possible edge point.   But I don't know how to apply threshold manually in matlab (step 3.). Can anyone help me? im1 = rgb2gray(imread('dog.jpg')); [gx,gy] = imgradientxy(im1); [gmag,gdir] = imgradient(gx,gy); imshow(gmag,[]);  
Expert Answer
Profile picture of Neeta Dsouza
Neeta Dsouza PhD Expert
Answered Aug 24, 2026
I think they wanted you to use imfilter() or conv2() to do it "manually". If you do want to go to a higher level, you should use imgradent() not imgradientxy - that gives you the magnitude directly. Then you can threshold it by adding this line:
 
 
binaryImage = gMag > someThresholdValue; % Threshold the image.

You don't need to do both imgradientxy() and imgradient().

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!