Demo entry 6628218

sobel

   

Submitted by sobel on Jul 02, 2017 at 09:32
Language: Matlab. Code size: 420 Bytes.

x_mask = [-1 -2 -1;0 0 0;1 2 1];%水平方向sobel模板
y_mask = x_mask';               %竖直方向sobel模板
I = im2double(A);               %转化为双精度
dx = imfilter(I, x_mask);       %水平方向梯度 
dy = imfilter(I, y_mask);       %竖直方向梯度
grad = sqrt(dx.*dx + dy.*dy);   % 计算总梯度 
grad = mat2gray(grad);  
BW = im2bw(grad,0.09);          %按照归一化阈值分割图像   
BW = 1 - BW;                    %图像反转
imshow(BW);                     % 显示分割后的图像即边缘图像 

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).