当前位置:首页 > 代码 > 正文

matlab双阈值分割代码(MATLAB阈值)

admin 发布:2022-12-19 15:47 118


本篇文章给大家谈谈matlab双阈值分割代码,以及MATLAB阈值对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

matlab任选阈值分割

I=imread('test.jpg');

subplot(1,3,1);

imshow(I);

title('原图');

I1=rgb2gray(I);

subplot(1,3,2);

imhist(I1);

title('直方图');

level=graythresh(I);

g=im2bw(I,level);%最佳阈值level subplo.

跪求matlab程序代码 关于医学图像分割处理 边缘检测 阈值法

图像分割程序:

% 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 :- car3.jpg

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 components.Here 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('lena.jpg');

imshow(I);

title('原始图像');

BW1= edge(I,'Canny',0.00) ; %edge调用Canny为检测算子判别阈值为0.00

figure,imshow(BW1);

title( '阈值为0.00的Canny算子边缘检测图像 ');

BW2= edge(I,'Canny',0.05) ; %edge调用Canny为检测算子判别阈值为0.05

figure,imshow(BW2);

title( '阈值为0.05的Canny算子边缘检测图像');

BW20= edge(I,'Canny',0.1) ; %edge调用Canny为检测算子判别阈值为0.1

figure,imshow(BW20);

title( '阈值为0.1的Canny算子边缘检测图像');

BW21= edge(I,'Canny',0.2) ; %edge调用Canny为检测算子判别阈值为0.2

figure,imshow(BW21);

title( '阈值为0.2的Canny算子边缘检测图像 ');

BW22= edge(I,'Canny',0.3) ; %edge调用Canny为检测算子判别阈值为0.3

figure,imshow(BW22);

title( '阈值为0.3的Canny算子边缘检测图像 ');

Matlab中Ostu算法自动阈值分割具体怎么操作

function threshold=ostu(filename);

x=imread(ff);

%figure;

%imshow(x);

[m,n]=size(x);

N=m*n;

num=zeros(1,256);

p=zeros(1,256);

for i=1:m

for j=1:n

num(x(i,j)+1)=num(x(i,j)+1)+1;

end

end

for i=0:255;

p(i+1)=num(i+1)/N;

end

totalmean=0;

for i=0:255;

totalmean=totalmean+i*p(i+1);

end

maxvar=0;

for k=0:255

kk=k+1;

zerosth=sum(p(1:kk));

firsth=0;

for h=0:k

firsth=firsth+h*p(h+1);

end

var=totalmean*zerosth-firsth;

var=var*var;

var=var/(zerosth*(1-zerosth)+0.01);

var=sqrt(var);

if(varmaxvar)

maxvar=var;

point=k;

end

end

threshold=point;

for i=0:255;

p(i+1)=num(i+1)/N;

end

totalmean=0;

for i=0:255;

totalmean=totalmean+i*p(i+1);

end

maxvar=0;

for k=0:255

kk=k+1;

zerosth=sum(p(1:kk));

matlab图像分割程序

clear I=imread('bai.jpg'); %读入图像

q=imadjust(I,[.2 .3 0;.6 .7 1],[]); %增强图像的对比度

j=rgb2gray(q); %彩色图像变灰度图像

j1=im2bw(q,230/255);%二值化

se90=strel('line',3,90); %构造元素

se0=strel('line',3,0); %同上

BW2=imdilate(j1,[se90 se0]); % 用构造的元素膨胀

BW3=bwareaopen(BW2,100);%开操作

BW3=~BW3;%取反

BW4=bwareaopen(BW3,20);%开

BW5=bwperim(BW4);%计算BW4周长

[imx,imy]=size(BW5);计算长宽

L=bwlabel(BW5,8);%用不同的数字根据是否连通标记图像,

a=max(max(L));%得到L图像中标记结果的最大值

BW6=bwfill(BW5,'hole');%填充背景

I2=I;

for i=1:3; I2(:,:,i)=I2(:,:,i).*uint8(BW6);

end imshow(I2); 有大神能逐条解释一下语句吗,本人是菜鸟啊,跪求!!

用matlab求图像阈值分析程序,急啊~

我给你提供2种方法,一种是直方图阈值法一种是最大类间方差

直方图阈值法

用 MATLAB实现直方图阈值法:

I=imread(' c4.jpg ');

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; %显示坐标系

自动阈值法:Otsu法

用MATLAB实现Otsu算法:

clc

clear all

I=imread(' c4.jpg ');

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; %显示坐标系

MATLAB--数字图像处理 Otsu算法(双阈值)

该算法就是利用otsu算法计算出两个阈值

公式

g=w0 (u0-u)^2+w1 (u1-u) ^2+ w2*(u2-u) ^2

g最大值时,就可以选出两个阈值

求两个阈值

利用这两个阈值分割图像

主函数调用

matlab双阈值分割代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于MATLAB阈值、matlab双阈值分割代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/11083.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载