资源描述:
《基于火灾监控数字图像程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、clear;clc;file_name=input('D:我的文档桌面数字图像资料火灾.jpg','s');I_rgb=imread('D:我的文档桌面数字图像资料火灾.jpg');figure();imshow(I_rgb)title('原始图像');C=makecform('srgb2lab');I_lab=applycform(I_rgb,C);ab=double(I_lab(:,:,2:3));nrows=size(ab,1);ncols=size(ab,2);ab=reshape(ab,nrows*ncols,2);nColors=3;[cluster_i
2、dxcluster_center]=kmeans(ab,nColors,'distance','sqEuclidean','Replicates',3);pixel_labels=reshape(cluster_idx,nrows,ncols);segmented_images=cell(1,3);rgb_label=repmat(pixel_labels,[113]);fork=1:nColorscolor=I_rgb;color(rgb_label~=k)=0;segmented_images{k}=color;endfigure(),imshow(segmented_imag
3、es{3}),title('分割结果——火焰');segmented_images{3}=rgb2gray(segmented_images{3});%以下灰度处理[rows,cols,colors]=size(segmented_images{3});B=zeros(rows,cols);B=uint8(B);C=zeros(rows,cols);C=uint8(C);fori=1:rowsforj=1:colssum1=0;sum2=0;fork=1:colorssum1=sum1+segmented_images{3}(i,j,k)/3;sum2=sum2+max(segme
4、nted_images{3}(i,j,k));endB(i,j)=sum1;C(i,j)=sum2;endendfigure();imshow(segmented_images{3}),title('灰度');[N,M]=size(segmented_images{3});%以下二值化length=N*M;L=256;count=0;fork=0:L-1fori=1:Nforj=1:Mifsegmented_images{3}(i,j)==kcount=count+1;endendendP(k+1)=count/length;count=0;endfori=1:LifP(i)~=0
5、first=i;breakendendfori=L:-1:1ifP(i)~=0last=i;breakendendentropy1=0;fori=first:lastif(P(i)~=0)entropy1=entropy1+P(i)*log2(1/P(i));endendep=0;averF=0;averB=0;fort=0:Ly=t+1;if(y>first)&&(y6、erB=averB+(i)*P(i)/w1(y);endu1(y)=averB;u=w0(y)*u0(y)+w1(y)*u1(y);arg(y)=w0(y)*(u0(y)-u)*(u0(y)-u)+w1(y)*(u1(y)-u)*(u1(y)-u);endep=0;averF=0;averB=0;endhigh=arg(1);fori=2:last-first-3ifhigh=t)y1(i,j)=255;I
7、1=I1+1;elsey1(i,j)=0;I0=I0+1;endendendfigure,imshow(y1);title('二值化');%(以上采用Otsu算法)figure;%以下为平滑J=fspecial('average');J1=filter2(J,y1)/255;subplot(1,3,2);imshow(J1);title('平滑');j=edge(J1,'canny',[0.04,0.25],1.5);%以下轮廓提取figure();imshow(j)