作为我的作业的一部分,我需要使用Sobel边缘检测计算并显示图像balls1.tif的边缘幅度图像和边缘方向图像。
请勿使用Matlab的edge函数,您可以使用conv2。 显示一个二值化边缘图像(1表示有边缘像素,0表示没有边缘),其中强的边缘像素上面有一个阈值。 确定一个阈值,以消除球阴影。
以下是我的main.m文件:
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
这是我的SobeEdgeDetection.m文件
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 < 101;
magnitude(thresh) = 0;
showImage(magnitude);
end
我的问题是:
1. 方向用于什么?如何显示它?
2. 有没有更好的方法获得一个阈值来消除球的阴影。我使用了试错法...
这是我展示大小的结果:
图片: