裂缝检测标记

闲来无事,做的一个小东西。效果图:

 既然能检测裂缝,那是不是……本来想开个车,奈何代码有bug,又不想改,就算了吧

 代码如下:

srcImg=imread('3.jpg');    %图片读取 
subplot(3,4,1);
imshow(srcImg);   
title('原始图像');

srcImg=rgb2gray(srcImg);   %灰度图
subplot(3,4,2);
imshow(srcImg);  


cropImg = imcrop(srcImg);     %裁剪图片
title('灰度图');
subplot(3,4,3);
imshow(cropImg);
title('裁剪图像');

adjImg=imadjust(cropImg,[0.40,0.75],[0,1]);   %区域增强
subplot(3,4,4);
imshow(adjImg);
title('区域增强');


H = fspecial('gaussian',2,2);          %滤波去噪
filImg = imfilter(adjImg,H,'replicate');
subplot(3,4,5);
imshow(filImg);
title('滤波去噪');


bwImgBig=im2bw(filImg,70/255);         %对灰度图像进行两次不同大小阈值的二值化,再把两次产生的二值化图像进行而至重构。
subplot(3,4,6);
imshow(~bwImgBig);
title('大阈值');

bwImgSmall=im2bw(filImg,30/255);
subplot(3,4,7);
imshow(~bwImgSmall);
title('小阈值');



recImg=imreconstruct(~bwImgSmall,~bwImgBig);   %去除图像边框干扰
[m,n]=size(recImg);
recImg(1,1:n)=0;
recImg(m,1:n)=0;
recImg(1:m,1)=0;
recImg(1:m,n)=0;
subplot(3,4,8);
imshow(recImg);
title('去除图像边框干扰');



%去除小于10的区域
recImg=bwareaopen(recImg,10);   %Bwareaopen函数是去除像素点少于十的连通区域
subplot(3,4,9);
imshow(recImg);
title('去除小于10的区域' );

%mark
[r,c]=size(recImg);
mark1=21;
col1=recImg(mark1,:);
col1=find(col1==1);
col1=round(length(col1)/2)+col1(1);

subplot(3,4,10);
imshow(recImg);
hold on; 
plot(col1,mark1, 'o','MarkerSize',20,'MarkerEdgeColor','r'); 

mark2=round(r/2);
col2=recImg(mark2,:);
col2=find(col2==1);
col2=round(length(col2)/2)+col2(1);
plot(col2,mark2, 'o','MarkerSize',20,'MarkerEdgeColor','r'); 


mark3=r-20;
col3=recImg(mark3,:);
col3=find(col3==1);
col3=round(length(col3)/2)+col3(1);
plot(col3,mark3, 'o','MarkerSize',20,'MarkerEdgeColor','r'); 


%计算宽度
[r,c]=size(recImg);
num=length(find(recImg==1));
avgPixel=num/m;
%普通对话框
h=dialog('name','宽度(pixel)','position',[700 500 200 70]);
uicontrol('parent',h,'style','text','string',avgPixel,'position',[10 40 120 20],'fontsize',12);
uicontrol('parent',h,'style','pushbutton','position',[80 10 50 20],'string','确定','callback','delete(gcbf)');

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值