Question
In Matlab , write the function gradient_magnitude that takes one input: a grayscale image (a matrix, not a filename). This function should return an image
In Matlab, write the function gradient_magnitude that takes one input: a grayscale image (a matrix, not a filename). This function should return an image (a matrix, not a file) of type double with the same dimensions as the input. This output contains the magnitude of the gradient. You should compute the gradient using the Sobel masks using your spatial_filter function(code below).
function [ output ] = spatial_filter( I,w )
%SPATIAL_FILTER Summary of this function goes here
% Detailed explanation goes here
%I = double(I);
[M,N] = size(I);
g = zeros(M+2,N+2);
for i = 1:M
for j = 1:N
g(i+1,j+1) = I(i,j);
end
end
for i = 1:M
for j = 1:N
output(i,j) = g(i,j)*w(1,1) + g(i+1,j)*w(2,1) + g(i+2,j)*w(3,1)...
+ g(i,j+1)*w(1,2) + g(i+1,j+1)*w(2,2) + g(i+2,j+1)*w(3,2)...
+ g(i,j+2)*w(1,3) + g(i+1,j+2)*w(2,3) + g(i+2,j+2)*w(3,3);
end
end
output = double(output)/255;
end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started