
matlab 边缘检测
我想问一下怎么对边缘检测后的图像进行二值分割。我编了一部分程序,可是二值分割实现不了。请教各位高招clear;closeallI=imread('road2.jpg');...
我想问一下怎么对边缘检测后的图像进行二值分割。我编了一部分程序,可是二值分割实现不了。请教各位高招
clear;close all
I=imread('road2.jpg');%读入原始jpg格式图像
figure
plot(1,1)
imshow(I)
W=size(I,2); %得到图像高度
I1=rgb2gray(I);%将原图像转化为灰度图象
figure;subplot(221);
imshow(I1);title('灰度图像');
I2=medfilt2(I1);%滤波默认窗口为[3,3]
subplot(222);imshow(I2);title('中值滤波结果');
I3=filter2(fspecial('average',3),I1)/255; %模板尺寸为3
subplot(223);imshow(I3);title('均值滤波结果');
I4=wiener2(I1,[3 3]); %对图像进行二维自适应维纳滤波
subplot(224);imshow(I4); title('自适应滤波结果');
J=[I1,I2,I3,I4];
for j=1:4;
Ij=J(:,1+W*(j-1):W*j); %%给Ij赋值
BW1=edge(Ij,'prewitt');%边缘检测
BW2=edge(Ij,'canny');
BW3=edge(Ij,'log');
BW4=edge(Ij,'sobel');
figure;
subplot(221);imshow(BW1);title('prewitt算子');
subplot(222);imshow(BW2);title('canny算子');
subplot(223);imshow(BW3);title('laplacian算子');
subplot(224);imshow(BW4);title('sobel算子');
end
figure;subplot(121);imhist(BW1);title('灰度直方图');%观察灰度直方图, 灰度直方图是空的,无法确定阈值,为什么呢?
I5=im2bw(BW1,T/255); % im2bw函数需要将灰度值转换到[0,1]范围内
subplot(122);imshow(I5);title('直方图阈值分割效果');
因为我是初学者,所以不太会编,希望能有一个完整的答案,谢谢 展开
clear;close all
I=imread('road2.jpg');%读入原始jpg格式图像
figure
plot(1,1)
imshow(I)
W=size(I,2); %得到图像高度
I1=rgb2gray(I);%将原图像转化为灰度图象
figure;subplot(221);
imshow(I1);title('灰度图像');
I2=medfilt2(I1);%滤波默认窗口为[3,3]
subplot(222);imshow(I2);title('中值滤波结果');
I3=filter2(fspecial('average',3),I1)/255; %模板尺寸为3
subplot(223);imshow(I3);title('均值滤波结果');
I4=wiener2(I1,[3 3]); %对图像进行二维自适应维纳滤波
subplot(224);imshow(I4); title('自适应滤波结果');
J=[I1,I2,I3,I4];
for j=1:4;
Ij=J(:,1+W*(j-1):W*j); %%给Ij赋值
BW1=edge(Ij,'prewitt');%边缘检测
BW2=edge(Ij,'canny');
BW3=edge(Ij,'log');
BW4=edge(Ij,'sobel');
figure;
subplot(221);imshow(BW1);title('prewitt算子');
subplot(222);imshow(BW2);title('canny算子');
subplot(223);imshow(BW3);title('laplacian算子');
subplot(224);imshow(BW4);title('sobel算子');
end
figure;subplot(121);imhist(BW1);title('灰度直方图');%观察灰度直方图, 灰度直方图是空的,无法确定阈值,为什么呢?
I5=im2bw(BW1,T/255); % im2bw函数需要将灰度值转换到[0,1]范围内
subplot(122);imshow(I5);title('直方图阈值分割效果');
因为我是初学者,所以不太会编,希望能有一个完整的答案,谢谢 展开
2个回答
展开全部
你看看workspace里面的的边缘检测后的图片BW1~BW4的值,会发现结果都已经被自动二值化了,当然得不出你想要的直方图。matlab估计觉得这些个边缘检测都是用于二值图的吧~
我也没找到输出灰度的edge函数,要不还是根据公式自己写吧,差分也挺容易的
我也没找到输出灰度的edge函数,要不还是根据公式自己写吧,差分也挺容易的
2010-06-02
展开全部
原始jpg格式图像
figure
plot(1,1)
imshow(I)
W=size(I,2); %得到图像高度
I1=rgb2gray(I);%将原图像转化为灰度图象
figure;subplot(221);
imshow(I1);title('灰度图像');
I2=medfilt2(I1);%滤波默认窗口为[3,3]
subplot(222);imshow(I2);title('中值滤波结果');
I3=filter2(fspecial('average',3),I1)/255; %模板尺
figure
plot(1,1)
imshow(I)
W=size(I,2); %得到图像高度
I1=rgb2gray(I);%将原图像转化为灰度图象
figure;subplot(221);
imshow(I1);title('灰度图像');
I2=medfilt2(I1);%滤波默认窗口为[3,3]
subplot(222);imshow(I2);title('中值滤波结果');
I3=filter2(fspecial('average',3),I1)/255; %模板尺
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询