xxx

灰度阈值法分割

clc;
clear all;
f=imread('E:\document\MATLAB\image\xxx2.png');
f1=im2bw(f,91/255);
f2=im2bw(f,140/255);
f3=im2bw(f,120/255);
f4=im2bw(f,56/255);
subplot(2,2,1);imshow(f1);
subplot(2,2,2);imshow(f2);
subplot(2,2,3);imshow(f3);
subplot(2,2,4);imshow(f4);
xxx_第1张图片
image.png

全局阈值分割

clc;
clear all;
I=imread('E:\document\MATLAB\image\xxx2.png'); 
subplot(1,2,1);
imshow(I);
level = graythresh(I);  %求取二值化的阈值
BW = im2bw(I, level);   %按阈值进行二值化
subplot(1,2,2);
imshow(BW);
xxx_第2张图片
image.png

局部阈值分割

clc;
clear all;
n=imread('E:\document\MATLAB\image\xxx2.png'); 
f=rgb2gray(n);
T = graythresh(f);                          % 自动获取阈值
T = T*255;                                % 阈值在区间[0,1],需调整至[0,255]
g = f>T;
subplot(1,2,1);imshow(f);title('原图像');
subplot(1,2,2);imshow(g);title(['阈值处理,阈值为' num2str(T)]);
xxx_第3张图片
image.png

你可能感兴趣的:(xxx)