1、大津法:functiony1=OTSU(image,th_set)image=imread('color1.bmp');gray=rgb2gray(image);%原图像的灰度图low_high=stretchlim(gray);%增强图像,似乎也不是一定需要gray=imadjust(gray,low_high,[]);%subplot(224);imshow(gray);title('afteradjust');count=imhist(gray);[r,t]=size(gray);n=r*t;l=256;count=count/n;%各级灰度出现的概率fori=2:l i
4、ori=1:r forj=1:t if(x1(i,j)>th) y1(i,j)=x1(i,j); else y1(i,j)=0; end endend%上面一段代码实现分割%figure,imshow(y1);%title('灰度门限分割的图像');程序二:clc; clear; cd 'D:My DocumentsMATLAB' time = now; I = imread('qr4.bmp'); figure(1),imshow(I