How to perform a thresholding operation on the gradient magnitude?

Technical Source
1 min readFeb 20, 2024

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);

NOTE:- provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

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().




Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.