当前位置: 代码迷 >> 其他开发语言 >> 跪求图像边缘检测sobel,canny等算子中随便一种的源程序
  详细解决方案

跪求图像边缘检测sobel,canny等算子中随便一种的源程序

热度:244   发布时间:2016-05-02 04:04:35.0
跪求图像边缘检测sobel,canny等算子中任意一种的源程序
我想请问一下知道不知道关于图像边缘检测sobel,canny等算子中任意一种的源程序。就是不要直接调用edge的程序,而是最最原始的程序代码?
clear all; 
close all; 
P=imread('D:\MATLAB\毕业论文图片\10组.jpg'); %读取图像
subplot(231);imshow(P); 
title('原图像'); 
d=size(P); 
if(d(3)>1)     
P=rgb2gray(P); 
end 
subplot(232);
imshow(P); 
title('灰度图像'); 
P=double(P);  
% Roberts Operator 
tou=input('input threshold tou='); 
bh=input('input a constant intensity nearer to white bh='); 
bl=input('input a constant intensity nearer to black bl=');
P1=P; 
for i=1:d(1)-1     
for j=1:d(2)-1 
RobNum=abs(P(i+1,j+1)-P(i,j))+abs(P(i,j+1)-P(i+1,j));    
     if RobNum>=tou             
     P1(i,j)=bh;         
         else             
     P1(i,j)=bl;         
         end     
     end 
end 
P1=uint8(P1); 
subplot(233);imshow(P1); 
title('Roberts Operator');
这段程序只能运行处原始图像和灰度图像,但是没有算子图像,我想问一下哪里出了问题?
还有tou=input('input threshold tou='); 
bh=input('input a constant intensity nearer to white bh='); 
bl=input('input a constant intensity nearer to black bl=');
这些括号里的参数应该设置成多少?
MATLAB 图片

------解决方案--------------------
RobNum=abs(P(i+1,j+1)-P(i,j))+abs(P(i,j+1)-P(i+1,j));    
这一句就是robert算子定义,是个近似运算.
Robert算子其实就是一个图像梯度处理,是一种交叉差分法。然后用用户指定的阀值来二值化图像.