clear; fid=fopen('d:\image\Lenaimg','r'); %打开无格式文件 data1=(fread(fid,[256,256],'uint8'))'; subplot(2,3,1),imagesc(data1); colormap(gray); title('LENA','Color','r'); subplot(2,3,2); data2=uint8(data1); R=edge(data2,'Roberts'); imagesc(R); title('Roberts检测算子'); subplot(2,3,3); data2=uint8(data1); Q=edge(data2,'Prewitt'); imagesc(Q); title('Prewitt检测算子'); subplot(2,3,4); data2=uint8(data1); S=edge(data2,'Sobel'); imagesc(S); title('Sobel检测算子'); subplot(2,3,5); data2=uint8(data1); T=edge(data2,'Log'); imagesc(T); title('Log检测算子'); Matlab中运行过的 正确的!
以下是一段MATLAB程序,经运行没问题。有注释,有分水岭算法。
afm = imread('cameramantif');figure, imshow(afm);
se = strel('disk', 15);
Itop = imtophat(afm, se); % 高帽变换
Ibot = imbothat(afm, se); % 低帽变换
figure, imshow(Itop, []); % 高帽变换,体现原始图像的灰度峰值
figure, imshow(Ibot, []); % 低帽变换,体现原始图像的灰度谷值
Ienhance = imsubtract(imadd(Itop, afm), Ibot);% 高帽图像与低帽图像相减,增强图像
figure, imshow(Ienhance);
Iec = imcomplement(Ienhance); % 进一步增强图像
Iemin = imextendedmin(Iec, 20); figure,imshow(Iemin) % 搜索Iec中的谷值
Iimpose = imimposemin(Iec, Iemin);
wat = watershed(Iimpose); % 分水岭分割
rgb = label2rgb(wat); figure, imshow(rgb); % 用不同的颜色表示分割出的不同区域
I = imread('lenabmp'); %%如果是其他类型图像,请先转换为灰度图
%%没有噪声时的检测结果
BW_sobel = edge(I,'sobel');
BW_prewitt = edge(I,'prewitt');
BW_roberts = edge(I,'roberts');
BW_laplace = edge(I,'log');
BW_canny = edge(I,'canny'); figure(1);
subplot(2,3,1),imshow(I),xlabel('原始图像');
subplot(2,3,2),imshow(BW_sobel),xlabel('sobel检测');
subplot(2,3,3),imshow(BW_prewitt),xlabel('prewitt检测');
subplot(2,3,4),imshow(BW_roberts),xlabel('roberts检测');
subplot(2,3,5),imshow(BW_laplace),xlabel('laplace检测');
subplot(2,3,6),imshow(BW_canny),xlabel('canny检测');
%%加入高斯噪声(μ=0,σ^2=001)检测结果
I_g1 = imnoise(I,'gaussian',0,001);
BW_sobel = edge(I_g1,'sobel');
BW_prewitt = edge(I_g1,'prewitt');
BW_roberts = edge(I_g1,'roberts');
BW_laplace = edge(I_g1,'log');
BW_canny = edge(I_g1,'canny'); figure(2);
subplot(2,3,1),imshow(I_g1),xlabel('加入高斯噪声(μ=0,σ^2=001)图像');
subplot(2,3,2),imshow(BW_sobel),xlabel('sobel检测');
subplot(2,3,3),imshow(BW_prewitt),xlabel('prewitt检测');
subplot(2,3,4),imshow(BW_roberts),xlabel('roberts检测');
subplot(2,3,5),imshow(BW_laplace),xlabel('laplace检测');
subplot(2,3,6),imshow(BW_canny),xlabel('canny检测');
%%加入高斯噪声(μ=0,σ^2=002)检测结果
I_g2 = imnoise(I,'gaussian',0,002);
BW_sobel = edge(I_g2,'sobel');
BW_prewitt = edge(I_g2,'prewitt');
BW_roberts = edge(I_g2,'roberts');
BW_laplace = edge(I_g2,'log');
BW_canny = edge(I_g2,'canny'); figure(3);
subplot(2,3,1),imshow(I_g2),xlabel('加入高斯噪声(μ=0,σ^2=002)图像');
subplot(2,3,2),imshow(BW_sobel),xlabel('sobel检测');
subplot(2,3,3),imshow(BW_prewitt),xlabel('prewitt检测');
subplot(2,3,4),imshow(BW_roberts),xlabel('roberts检测');
subplot(2,3,5),imshow(BW_laplace),xlabel('laplace检测');
subplot(2,3,6),imshow(BW_canny),xlabel('c
一、没有噪声时的检测结果 1 原始图像
2 Sobel算子边缘检测 3 Prewitt算子边缘检测 4 Roberts算子边缘检测 5 Laplace算子边缘检测 6 Canny算子边缘检测
二、加入高斯噪声(μ=0,σ^2=001)检测结果 1 原始图像
2 Sobel算子边缘检测 3 Prewitt算子边缘检测 4 Roberts算子边缘检测 5 Laplace算子边缘检测 6 Canny算子边缘检测
三、加入高斯噪声(μ=0,σ^2=002)检测结果 1 原始图像
2 Sobel算子边缘检测 3 Prewitt算子边缘检测 4 Roberts算子边缘检测 5 Laplace算子边缘检测 6 Canny算子边缘检测
clear all; close all;
warning off all;
clear all;
I=imread('');%自己输入路径
GryIm=rgb2gray(I);%变灰度,如果是灰度图,直接删掉它
BW=edge(GryIm,'sobel');%后边的参数‘sobel’或'roberts'自己改
subplot(2,2,1);imshow(I);title('Oringal Image');
subplot(2,2,2);imshow(BW);title('Edge detect of sobel');
图像分割程序:
% This is a program for extracting objects from an image Written for vehicle number plate segmentation and extraction
% Authors : Jeny Rajan, Chandrashekar P S
% U can use attached test image for testing
% input - give the image file name as input eg :- car3jpg
clc;
clear all;
k=input('Enter the file name','s'); % input image; color image
im=imread(k);
im1=rgb2gray(im);
im1=medfilt2(im1,[3 3]); %Median filtering the image to remove noise%
BW = edge(im1,'sobel'); %finding edges
[imx,imy]=size(BW);
msk=[0 0 0 0 0;
0 1 1 1 0;
0 1 1 1 0;
0 1 1 1 0;
0 0 0 0 0;];
B=conv2(double(BW),double(msk)); %Smoothing image to reduce the number of connected components
L = bwlabel(B,8);% Calculating connected components
mx=max(max(L))
% There will be mx connected componentsHere U can give a value between 1 and mx for L or in a loop you can extract all connected components
% If you are using the attached car image, by giving 17,18,19,22,27,28 to L you can extract the number plate completely
[r,c] = find(L==17);
rc = [r c];
[sx sy]=size(rc);
n1=zeros(imx,imy);
for i=1:sx
x1=rc(i,1);
y1=rc(i,2);
n1(x1,y1)=255;
end % Storing the extracted image in an array
figure,imshow(im);
figure,imshow(im1);
figure,imshow(B);
figure,imshow(n1,[]);
边缘检测:
I=imread('lenajpg');
imshow(I);
title('原始图像');
BW1= edge(I,'Canny',000) ; %edge调用Canny为检测算子判别阈值为000
figure,imshow(BW1);
title( '阈值为000的Canny算子边缘检测图像 ');
BW2= edge(I,'Canny',005) ; %edge调用Canny为检测算子判别阈值为005
figure,imshow(BW2);
title( '阈值为005的Canny算子边缘检测图像');
BW20= edge(I,'Canny',01) ; %edge调用Canny为检测算子判别阈值为01
figure,imshow(BW20);
title( '阈值为01的Canny算子边缘检测图像');
BW21= edge(I,'Canny',02) ; %edge调用Canny为检测算子判别阈值为02
figure,imshow(BW21);
title( '阈值为02的Canny算子边缘检测图像 ');
BW22= edge(I,'Canny',03) ; %edge调用Canny为检测算子判别阈值为03
figure,imshow(BW22);
title( '阈值为03的Canny算子边缘检测图像 ');
close all
clear all
I=imread('tigjpg'); %读取图像
I1=im2double(I); %将彩图序列变成双精度
I2=rgb2gray(I1); %将彩色图变成灰色图
[thr, sorh, keepapp]=ddencmp('den','wv',I2);
I3=wdencmp('gbl',I2,'sym4',2,thr,sorh,keepapp); %小波除噪
I4=medfilt2(I3,[9 9]); %中值滤波
I5=imresize(I4,02,'bicubic'); %图像大小
BW1=edge(I5,'sobel'); %sobel图像边缘提取
BW2=edge(I5,'roberts'); %roberts图像边缘提取
BW3=edge(I5,'prewitt'); %prewitt图像边缘提取
BW4=edge(I5,'log'); %log图像边缘提取
BW5=edge(I5,'canny'); %canny图像边缘提取
h=fspecial('gaussian',5); %高斯滤波
BW6=edge(I5,'zerocross',[ ],h); %zerocross图像边缘提取
figure;
subplot(1,3,1); %图划分为一行三幅图,第一幅图
imshow(I2); %绘图
figure;
subplot(1,3,1);
imshow(BW1);
title('Sobel算子');
subplot(1,3,2);
imshow(BW2);
title('Roberts算子');
subplot(1,3,3);
imshow(BW3);
title('Prewitt算子');
以上就是关于能否编写一个用matlab实现的基于Roberts算子的图像边缘检测程序全部的内容,包括:能否编写一个用matlab实现的基于Roberts算子的图像边缘检测程序、寻找分水岭,canny边缘检测的matlab程序~、matlab canny算子边缘检测函数代码是什么等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)