❶ matlab圖像邊緣檢測 背景變全黑
圖像可否發上來?
你這段是不是從別人的程序粘貼過來的
那程序是使用不同辦法求圖像邊緣,然後比較結果的
而按你的描述你需要的結果,只是想把背景變黑
好像不需要幾種求邊緣的辦法
而且如果只是要背景變黑
那麼分出前景背景就可以,不需要提取邊緣
❷ Matlab中如何實現灰度膨脹和灰度腐蝕
1、選取函數為f(x)=-|x-6|+5在[1,11]上的圖像,畫出函數圖像。
❸ 數字圖像處理 膨脹和腐蝕演算法的實現
腐蝕的演算法:
用3x3的結構元素,掃描圖像的每一個像素
用結構元素與其覆蓋的二值圖像做「與」操作
如果都為1,結果圖像的該像素為1。否則為0。
結果:使二值圖像減小一圈
定義:E = B S = { x,y | SxyB}
膨脹的演算法:
用3x3的結構元素,掃描圖像的每一個像素
用結構元素與其覆蓋的二值圖像做「與」操作
如果都為0,結果圖像的該像素為0。否則為1
結果:使二值圖像擴大一圈
定義:E = B S = { x,y | Sxy∩B ≠Ф}
❹ 圖像污垢檢測用什麼方法,matlab編程
1、用Prewitt運算元檢測圖像的邊緣
I = imread('bacteria.BMP');
BW1 = edge(I,'prewitt',0.04); % 0.04為梯度閾值
figure(1);
imshow(I);
figure(2);
imshow(BW1);
2、用不同σ值的LoG運算元檢測圖像的邊緣
I = imread('bacteria.BMP');
BW1 = edge(I,'log',0.003); % σ=2
imshow(BW1);title('σ=2')
BW1 = edge(I,'log',0.003,3); % σ=3
figure, imshow(BW1);title('σ=3')
3、用Canny運算元檢測圖像的邊緣
I = imread('bacteria.BMP');
imshow(I);
BW1 = edge(I,'canny',0.2);
figure,imshow(BW1);
4、圖像的閾值分割
I=imread('blood1.tif');
imhist(I); % 觀察灰度直方圖, 灰度140處有谷,確定閾值T=140
I1=im2bw(I,140/255); % im2bw函數需要將灰度值轉換到[0,1]范圍內
figure,imshow(I1);
5、用水線閾值法分割圖像
afm = imread('afmsurf.tif');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); % 用不同的顏色表示分割出的不同區域
6、對矩陣進行四叉樹分解
I = [ 1 1 1 1 2 3 6 6
1 1 2 1 4 5 6 8
1 1 1 1 10 15 7 7
1 1 1 1 20 25 7 7
20 22 20 22 1 2 3 4
20 22 22 20 5 6 7 8
20 22 20 20 9 10 11 12
22 22 20 20 13 14 15 16];
S = qtdecomp(I,5);
full(S)
7、將圖像分為文字和非文字的兩個類別
I=imread('4-11.jpg');
I1=I(:,:,1);
I2=I(:,:,2);
I3=I(:,:,3);
[y,x,z]=size(I);
d1=zeros(y,x);
d2=d1;
myI=double(I);
I0=zeros(y,x);
for i=1:x
for j=1:y
%歐式聚類
d1(j,i)=sqrt((myI(j,i,1)-180)^2+(myI(j,i,2)-180)^2+(myI(j,i,3)-180)^2);
d2(j,i)=sqrt((myI(j,i,1)-200)^2+(myI(j,i,2)-200)^2+(myI(j,i,3)-200)^2);
if (d1(j,i)>=d2(j,i))
I0(j,i)=1;
end
end
end
figure(1);
imshow(I);
% 顯示RGB空間的灰度直方圖,確定兩個聚類中心(180,180,180)和(200,200,200)
figure(2);
subplot(1,3,1);
imhist(I1);
subplot(1,3,2);
imhist(I2);
subplot(1,3,3);
imhist(I3);
figure(4);
imshow(I0);
8、形態學梯度檢測二值圖像的邊緣
I=imread('wrod213.bmp');
imshow(I);
I=~I; % 腐蝕運算對灰度值為1的進行
figure, imshow(I);
SE=strel('square',3); % 定義3×3腐蝕結構元素
J=imerode(~I,SE);
BW=(~I)-J; % 檢測邊緣
figure,imshow(BW);
9、形態學實例——從PCB圖像中刪除所有電流線,僅保留晶元對象
I=imread('circbw.tif');
imshow(I);
SE=strel('rectangle',[40 30]); % 結構定義
J=imopen(I,SE); % 開啟運算
figure,imshow(J);
❺ 求matlab實現膨脹腐蝕程序
就算給了代碼,看起來也要費一番精神的,特別是演算法不熟悉的
clear,clc;
h=imread('ceshi2.bmp');
i=im2bw(h);
i1i=187;
i1j=192;
forai=181:193
foraj=186:198
if(sqrt(double(ai-i1i)^2+double(aj-i1j)^2)<=5)
i(ai,aj)=1;%定義圓形結構元素
end
end
end
figure,imshow(i);
i1=i;
fori1i=6:205%用B腐蝕A
fori1j=6:205
flag=0;
if(i1i>=181&&i1i<=193&&i1j>=186&&i1j<=198)
continue;
else
if(i(i1i,i1j)==1)
forai=i1i-5:i1i+5
foraj=i1j-5:i1j+5
if(i1(ai,aj)==0&&sqrt(double((ai-i1i)^2+(aj-i1j)^2))<=5)
i(i1i,i1j)=0;
flag=1;
break;
end
end
if(flag==1)
break;
end
end
end
end
end
end
figure,imshow(i);
%在上面C的圖像上用B進行膨脹
i2=i;
fori1i=6:205%用B膨脹C
fori1j=6:205
flag=0;
if(i1i>=175&&i1i<=199&&i1j>=180&&i1j<=204)
continue;
else
forai=i1i-5:i1i+5
foraj=i1j-5:i1j+5
if(i2(ai,aj)==1&&sqrt(double((ai-i1i)^2+(aj-i1j)^2))<=5)
i(i1i,i1j)=1;
flag=1;
break;
end
end
if(flag==1)
break;
end
end
end
end
end
figure,imshow(i);
%在上面D的圖像上用B進行膨脹
i2=i;
fori1i=6:205%用B膨脹D
fori1j=6:205
flag=0;
if(i1i>=175&&i1i<=199&&i1j>=180&&i1j<=204)
continue;
else
forai=i1i-5:i1i+5
foraj=i1j-5:i1j+5
if(i2(ai,aj)==1&&sqrt(double((ai-i1i)^2+(aj-i1j)^2))<=5)
i(i1i,i1j)=1;
flag=1;
break;
end
end
if(flag==1)
break;
end
end
end
end
end
figure,imshow(i);
%在上面E的圖像上用B進行腐蝕
i1=i;
fori1i=6:205%用B腐蝕E
fori1j=6:205
flag=0;
if(i1i>=181&&i1i<=193&&i1j>=186&&i1j<=198)
continue;
else
if(i(i1i,i1j)==1)
forai=i1i-5:i1i+5
foraj=i1j-5:i1j+5
if(i1(ai,aj)==0&&sqrt(double((ai-i1i)^2+(aj-i1j)^2))<=5)
i(i1i,i1j)=0;
flag=1;
break;
end
end
if(flag==1)
break;
end
end
end
end
end
end
figure,imshow(i);
❻ 用MATLAB的數學形態學做圖像分割的步驟是什麼啊 先腐蝕在膨脹 還是說先得用到邊緣檢測什麼的
% rgb=imread('source1.bmp');
% I=rgb2gray(rgb); % 色彩轉換成灰度
I=imread('source3.bmp');
level= graythresh(I); %得到合適的閾值 得到合適的閾值
bw= im2bw(I,level); %二值化
SE= strel('square',3); %設置膨脹結構元素
BW1= imdilate(bw,SE); % 膨脹
SE1= strel('arbitrary',eye(5)); %設置腐蝕結構元素
BW2= imerode(bw,SE1); %腐蝕
BW3= bwmorph(bw,'open'); %開運算
BW4= bwmorph(bw,'close'); %閉運算
figure(1),
subplot(2,3,1),imshow(I);title('原圖');
subplot(2,3,2),imshow(bw);title('二值圖');
subplot(2,3,3),imshow(BW1);title('膨脹');
subplot(2,3,4),imshow(BW2);title('腐蝕');
subplot(2,3,5),imshow(BW3);title('開運算');
subplot(2,3,6),imshow(BW4);title('閉運算');
%
figure(2)
BW5 = imfill(bw,'holes');
subplot(121), imshow(bw), title('源圖像二值化')
subplot(122), imshow(BW5), title('填充後的圖像')
%輪廓提取
figure(3)
contour = bwperim(bw);
imshow(contour);
title('輪廓')
❼ 求MATLAB代碼
MATLAB實用源代碼
1圖像的讀取及旋轉
A=imread('');%讀取圖像
subplot(2,2,1),imshow(A),title('原始圖像');%輸出圖像
I=rgb2gray(A);
subplot(2,2,2),imshow(A),title('灰度圖像');
subplot(2,2,3),imhist(I),title('灰度圖像直方圖');%輸出原圖直方圖
theta = 30;J = imrotate(I,theta);% Try varying the angle, theta.
subplot(2,2,4), imshow(J),title(『旋轉圖像』)
2邊緣檢測
I=imread('C:\Users\HP\Desktop\平時總結\路飛.jpg');
subplot(2,2,1),imshow(I),title('原始圖像');
I1=edge(I,'sobel');
subplot(2,2,2),imshow(I1),title('sobel邊緣檢測');
I2=edge(I,'prewitt');
subplot(2,2,3),imshow(I2),title('prewitt邊緣檢測');
I3=edge(I,'log');
subplot(2,2,4),imshow(I3),title('log邊緣檢測');
3圖像反轉
MATLAB 程序實現如下:
I=imread('xian.bmp');
J=double(I);
J=-J+(256-1);%圖像反轉線性變換
H=uint8(J);
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(H);
4.灰度線性變換
MATLAB 程序實現如下:
I=imread('xian.bmp');
subplot(2,2,1),imshow(I);
title('原始圖像');
axis([50,250,50,200]);
axis on;%顯示坐標系
I1=rgb2gray(I);
subplot(2,2,2),imshow(I1);
title('灰度圖像');
axis([50,250,50,200]);
axis on; %顯示坐標系
J=imadjust(I1,[0.1 0.5],[]); %局部拉伸,把[0.1 0.5]內的灰度拉伸為[0 1]
subplot(2,2,3),imshow(J);
title('線性變換圖像[0.1 0.5]');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
K=imadjust(I1,[0.3 0.7],[]); %局部拉伸,把[0.3 0.7]內的灰度拉伸為[0 1]
subplot(2,2,4),imshow(K);
title('線性變換圖像[0.3 0.7]');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
5.非線性變換
MATLAB 程序實現如下:
I=imread('xian.bmp');
I1=rgb2gray(I);
subplot(1,2,1),imshow(I1);
title(' 灰度圖像');
axis([50,250,50,200]);
grid on;%顯示網格線
axis on;%顯示坐標系
J=double(I1);
J=40*(log(J+1));
H=uint8(J);
subplot(1,2,2),imshow(H);
title(' 對數變換圖像');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
4.直方圖均衡化
MATLAB 程序實現如下:
I=imread('xian.bmp');
I=rgb2gray(I);
figure;
subplot(2,2,1);
imshow(I);
subplot(2,2,2);
imhist(I);
I1=histeq(I);
figure;
subplot(2,2,1);
imshow(I1);
subplot(2,2,2);
imhist(I1);
5. 線性平滑濾波器
用MATLAB實現領域平均法抑制雜訊程序:
I=imread('xian.bmp');
subplot(231)
imshow(I)
title('原始圖像')
I=rgb2gray(I);
I1=imnoise(I,'salt & pepper',0.02);
subplot(232)
imshow(I1)
title(' 添加椒鹽雜訊的圖像')
k1=filter2(fspecial('average',3),I1)/255; %進行3*3模板平滑濾波
k2=filter2(fspecial('average',5),I1)/255; %進行5*5模板平滑濾波k3=filter2(fspecial('average',7),I1)/255; %進行7*7模板平滑濾波
k4=filter2(fspecial('average',9),I1)/255; %進行9*9模板平滑濾波
subplot(233),imshow(k1);title('3*3 模板平滑濾波');
subplot(234),imshow(k2);title('5*5 模板平滑濾波');
subplot(235),imshow(k3);title('7*7 模板平滑濾波');
subplot(236),imshow(k4);title('9*9 模板平滑濾波');
6.中值濾波器
用MATLAB實現中值濾波程序如下:
I=imread('xian.bmp');
I=rgb2gray(I);
J=imnoise(I,'salt&pepper',0.02);
subplot(231),imshow(I);title('原圖像');
subplot(232),imshow(J);title('添加椒鹽雜訊圖像');
k1=medfilt2(J); %進行3*3模板中值濾波
k2=medfilt2(J,[5,5]); %進行5*5模板中值濾波
k3=medfilt2(J,[7,7]); %進行7*7模板中值濾波
k4=medfilt2(J,[9,9]); %進行9*9模板中值濾波
subplot(233),imshow(k1);title('3*3模板中值濾波');
subplot(234),imshow(k2);title('5*5模板中值濾波 ');
subplot(235),imshow(k3);title('7*7模板中值濾波');
subplot(236),imshow(k4);title('9*9 模板中值濾波');
7.用Sobel運算元和拉普拉斯對圖像銳化:
I=imread('xian.bmp');
subplot(2,2,1),imshow(I);
title('原始圖像');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on;%顯示坐標系
I1=im2bw(I);
subplot(2,2,2),imshow(I1);
title('二值圖像');
axis([50,250,50,200]);
grid on;%顯示網格線
axis on;%顯示坐標系
H=fspecial('sobel');%選擇sobel運算元
J=filter2(H,I1); %卷積運算
subplot(2,2,3),imshow(J);
title('sobel運算元銳化圖像');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on;%顯示坐標系
h=[0 1 0,1 -4 1,0 1 0]; %拉普拉斯運算元
J1=conv2(I1,h,'same');%卷積運算
subplot(2,2,4),imshow(J1);
title('拉普拉斯運算元銳化圖像');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
8.梯度運算元檢測邊緣
用 MATLAB實現如下:
I=imread('xian.bmp');
subplot(2,3,1);
imshow(I);
title('原始圖像');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
I1=im2bw(I);
subplot(2,3,2);
imshow(I1);
title('二值圖像');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
I2=edge(I1,'roberts');
figure;
subplot(2,3,3);
imshow(I2);
title('roberts運算元分割結果');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
I3=edge(I1,'sobel');
subplot(2,3,4);
imshow(I3);
title('sobel運算元分割結果');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
I4=edge(I1,'Prewitt');
subplot(2,3,5);
imshow(I4);
title('Prewitt運算元分割結果 ');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
9.LOG運算元檢測邊緣
用 MATLAB程序實現如下:
I=imread('xian.bmp');
subplot(2,2,1);
imshow(I);
title('原始圖像');
I1=rgb2gray(I);
subplot(2,2,2);
imshow(I1);
title('灰度圖像');
I2=edge(I1,'log');
subplot(2,2,3);
imshow(I2);
title('log運算元分割結果');
10.Canny運算元檢測邊 緣
用MATLAB程序實現如下:
I=imread('xian.bmp');
subplot(2,2,1);
imshow(I);
title('原始圖像')
I1=rgb2gray(I);
subplot(2,2,2);
imshow(I1);
title('灰度圖像');
I2=edge(I1,'canny');
subplot(2,2,3);
imshow(I2);
title('canny運算元分割結果');
11.邊界跟蹤 (bwtraceboundary函數)
clc
clear all
I=imread('xian.bmp');
figure
imshow(I);
title('原始圖像');
I1=rgb2gray(I); %將彩色圖像轉化灰度圖像
threshold=graythresh(I1); %計算將灰度圖像轉化為二值圖像所需的門限
BW=im2bw(I1, threshold); %將灰度圖像轉化為二值圖像
figure
imshow(BW);
title('二值圖像');
dim=size(BW);
col=round(dim(2)/2)-90; %計算起始點列坐標
row=find(BW(:,col),1); %計算起始點行坐標
connectivity=8;
num_points=180;
contour=bwtraceboundary(BW,[row,col],'N',connectivity,num_points);
%提取邊界
figure
imshow(I1);
hold on;
plot(contour(:,2),contour(:,1), 'g','LineWidth' ,2);
title('邊界跟蹤圖像');
12.Hough變換
I= imread('xian.bmp');
rotI=rgb2gray(I);
subplot(2,2,1);
imshow(rotI);
title('灰度圖像');
axis([50,250,50,200]);
grid on;
axis on;
BW=edge(rotI,'prewitt');
subplot(2,2,2);
imshow(BW);
title('prewitt運算元邊緣檢測 後圖像');
axis([50,250,50,200]);
grid on;
axis on;
[H,T,R]=hough(BW);
subplot(2,2,3);
imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit');
title('霍夫變換圖');
xlabel('\theta'),ylabel('\rho');
axis on , axis normal, hold on;
P=houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x=T(P(:,2));y=R(P(:,1));
plot(x,y,'s','color','white');
lines=houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
subplot(2,2,4);,imshow(rotI);
title('霍夫變換圖像檢測');
axis([50,250,50,200]);
grid on;
axis on;
hold on;
max_len=0;
for k=1:length(lines)
xy=[lines(k).point1;lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
len=norm(lines(k).point1-lines(k).point2);
if(len>max_len)
max_len=len;
xy_long=xy;
end
end
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','cyan');
13.直方圖閾值法
用 MATLAB實現直方圖閾值法:
I=imread('xian.bmp');
I1=rgb2gray(I);
figure;
subplot(2,2,1);
imshow(I1);
title(' 灰度圖像')
axis([50,250,50,200]);
grid on;%顯示網格線
axis on; %顯示坐標系
[m,n]=size(I1);%測量圖像尺寸參數
GP=zeros(1,256); %預創建存放灰度出現概率的向量
for k=0:255
GP(k+1)=length(find(I1==k))/(m*n);%計算每級灰度出現的概率,將其存入GP中相應位置
end
subplot(2,2,2),bar(0:255,GP,'g')%繪制直方圖
title('灰度直方圖')
xlabel('灰度值')
ylabel(' 出現概率')
I2=im2bw(I,150/255);
subplot(2,2,3),imshow(I2);
title('閾值150的分割圖像')
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
I3=im2bw(I,200/255); %
subplot(2,2,4),imshow(I3);
title('閾值200的分割圖像')
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
14. 自動閾值法:Otsu法
用MATLAB實現Otsu演算法:
clc
clear all
I=imread('xian.bmp');
subplot(1,2,1),imshow(I);
title('原始圖像')
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
level=graythresh(I); %確定灰度閾值
BW=im2bw(I,level);
subplot(1,2,2),imshow(BW);
title('Otsu 法閾值分割圖像')
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
15.膨脹操作
I=imread('xian.bmp'); %載入圖像
I1=rgb2gray(I);
subplot(1,2,1);
imshow(I1);
title('灰度圖像')
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
se=strel('disk',1); %生成圓形結構元素
I2=imdilate(I1,se); %用生成的結構元素對圖像進行膨脹
subplot(1,2,2);
imshow(I2);
title(' 膨脹後圖像');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
16.腐蝕操作
MATLAB 實現腐蝕操作
I=imread('xian.bmp'); %載入圖像
I1=rgb2gray(I);
subplot(1,2,1);
imshow(I1);
title('灰度圖像')
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
se=strel('disk',1); %生成圓形結構元素
I2=imerode(I1,se); %用生成的結構元素對圖像進行腐蝕
subplot(1,2,2);
imshow(I2);
title('腐蝕後圖像');
axis([50,250,50,200]);
grid on; %顯示網格線
axis on; %顯示坐標系
17.開啟和閉合操作
用 MATLAB實現開啟和閉合操作
I=imread('xian.bmp'); %載入圖像
subplot(2,2,1),imshow(I);
title('原始圖像');
axis([50,250,50,200]);
axis on; %顯示坐標系
I1=rgb2gray(I);
subplot(2,2,2),imshow(I1);
title('灰度圖像');
axis([50,250,50,200]);
axis on; %顯示坐標系
se=strel('disk',1); %採用半徑為1的圓作為結構元素
I2=imopen(I1,se); %開啟操作
I3=imclose(I1,se); %閉合操作
subplot(2,2,3),imshow(I2);
title('開啟運算後圖像');
axis([50,250,50,200]);
axis on; %顯示坐標系
subplot(2,2,4),imshow(I3);
title('閉合運算後圖像');
axis([50,250,50,200]);
axis on; %顯示坐標系
18.開啟和閉合組合操作
I=imread('xian.bmp');%載入圖像
subplot(3,2,1),imshow(I);
title('原始圖像');
axis([50,250,50,200]);
axis on;%顯示坐標系
I1=rgb2gray(I);
subplot(3,2,2),imshow(I1);
title('灰度圖像');
axis([50,250,50,200]);
axis on;%顯示坐標系
se=strel('disk',1);
I2=imopen(I1,se);%開啟操作
I3=imclose(I1,se);%閉合操作
subplot(3,2,3),imshow(I2);
title('開啟運算後圖像');
axis([50,250,50,200]);
axis on;%顯示坐標系
subplot(3,2,4),imshow(I3);
title('閉合運算後圖像');
axis([50,250,50,200]);
axis on;%顯示坐標系
se=strel('disk',1);
I4=imopen(I1,se);
I5=imclose(I4,se);
subplot(3,2,5),imshow(I5);%開—閉運算圖像
title('開—閉運算圖像');
axis([50,250,50,200]);
axis on;%顯示坐標系
I6=imclose(I1,se);
I7=imopen(I6,se);
subplot(3,2,6),imshow(I7);%閉—開運算圖像
title('閉—開運算圖像');
axis([50,250,50,200]);
axis on;%顯示坐標系
19.形態學邊界提取
利用 MATLAB實現如下:
I=imread('xian.bmp');%載入圖像
subplot(1,3,1),imshow(I);
title('原始圖像');
axis([50,250,50,200]);
grid on;%顯示網格線
axis on;%顯示坐標系
I1=im2bw(I);
subplot(1,3,2),imshow(I1);
title('二值化圖像');
axis([50,250,50,200]);
grid on;%顯示網格線
axis on;%顯示坐標系
I2=bwperim(I1); %獲取區域的周長
subplot(1,3,3),imshow(I2);
title('邊界周長的二值圖像');
axis([50,250,50,200]);
grid on;
axis on;
20.形態學骨架提取
利用MATLAB實現如下:
I=imread('xian.bmp');
subplot(2,2,1),imshow(I);
title('原始圖像');
axis([50,250,50,200]);
axis on;
I1=im2bw(I);
subplot(2,2,2),imshow(I1);
title('二值圖像');
axis([50,250,50,200]);
axis on;
I2=bwmorph(I1,'skel',1);
subplot(2,2,3),imshow(I2);
title('1次骨架提取');
axis([50,250,50,200]);
axis on;
I3=bwmorph(I1,'skel',2);
subplot(2,2,4),imshow(I3);
title('2次骨架提取');
axis([50,250,50,200]);
axis on;
21.直接提取四個頂點坐標
I = imread('xian.bmp');
I = I(:,:,1);
BW=im2bw(I);
figure
imshow(~BW)
[x,y]=getpts
平滑濾波
h=fspecial('average',9);
I_gray=imfilter(I_gray,h,'replicate');%平滑濾波
❽ matlab形態學處理——膨脹腐蝕的原理
在matlab定義裡面,這兩個函數本來就是能夠作用於灰度圖像的,看幫助文件你也能看到
作用與灰度圖的例子
當然,膨脹和腐蝕多用於處理二值圖像
先把輸入的圖像二值化成為二值圖像,在用這兩個函數就可以了
❾ 關於matlab中imerode函數
Matlab用imerode函數實現圖像腐蝕。用法為:Imerode(X,SE).其中X是待處理的圖像,SE是結構元素對象。而結構元素的選擇對圖像處理結果有很大關系,我想請問一下 對大寫的英文字母的腐蝕 取怎麼樣的結構元素比較合適.
MATLAB是美國MathWorks公司出品的商業數學軟體,用於演算法開發、數據可視化、數據分析以及數值計算的高級技術計算語言和互動式環境,主要包括MATLAB和Simulink兩大部分。MATLAB應用非常之廣泛!
基本介紹
MATLAB(矩陣實驗室)是MATrix LABoratory的縮寫,是一款由美國The MathWorks公司出品的商業數學軟體。MATLAB是一種用於演算法開發、數據可視化、數據分析以及數值計算的高級技術計算語言和互動式環境。除了矩陣運算、繪制函數/數據圖像等常用功能外,MATLAB還可以用來創建用戶界面及與調用其它語言(包括C,C++和FORTRAN)編寫的程序。
盡管MATLAB主要用於數值運算,但利用為數眾多的附加工具箱(Toolbox)它也適合不同領域的應用,例如控制系統設計與分析、圖像處理、信號處理與通訊、金融建模和分析等。另外還有一個配套軟體包Simulink,提供了一個可視化開發環境,常用於系統模擬、動態/嵌入式系統開發等方面。
MATLAB和Mathematica、Maple並稱為三大數學軟體。它在數學類科技應用軟體中在數值計算方面首屈一指。MATLAB可以進行矩陣運算、繪制函數和數據、實現演算法、創建用戶界面、連接其他編程語言的程序等,主要應用於工程計算、控制設計、信號處理與通訊、圖像處理、信號檢測、金融建模設計與分析等領域。
MATLAB的基本數據單位是矩陣,它的指令表達式與數學、工程中常用的形式十分相似,故用MATLAB來解算問題要比用C,FORTRAN等語言完成相同的事情簡捷得多,並且MATLAB也吸收了像Maple等軟體的優點,使MATLAB成為一個強大的數學軟體。在新的版本中也加入了對C,FORTRAN,C++,JAVA的支持。可以直接調用,用戶也可以將自己編寫的實用程序導入到MATLAB函數庫中方便自己以後調用,此外許多的MATLAB愛好者都編寫了一些經典的程序,用戶可以直接進行下載就可以用。