A matlab code for detection of tiles on production line


As our tutor is interested in cooperating with company, we are working on a project to detect tiles on the production line. Image processing with matlab, we can determine the position and rotation of the tile correctly.

Codes are below:

tic

%预设值
bwg=0.3;%二值化阈值
siz=[10700,11400];%瓷砖面积最大最小值

%统计各区域大小
I=imread('图像00012.bmp');
Ibw=im2bw(I,bwg);
I2=zeros(size(Ibw));
[L,num]=bwlabel(Ibw);
s=zeros(num,1);
for i=1:num
[r,c]=find(L==i);
[r1,c1]=size(r);
s(i,1)=r1;
end

%保留符合条件的瓷砖
Itile=zeros(size(Ibw));
for i=1:num
[r,c]=find(L==i);
[r1,c1]=size(r);
if r1>siz(1) & r1point2(1)+point2(2)
			point2(1)=r(j);
			point2(2)=c(j);
		end
		if r(j)>point3(1)
			point3(1)=r(j);
			point3(2)=c(j);
		end
	end
	loc(i,1)=round((point1(1)+point2(1))*0.5);
	loc(i,2)=round((point1(2)+point2(2))*0.5);
	if point3(2)point3(1)& c(j)==c(1)
				point3(1)=r(j);
			end
		end
		loc(i,3)=-180*atan((point2(1)-point3(1))/(point2(2)-point3(2)));
	end
end 
loc

%效果显示
I2=I;
[high,wide]=size(I);
for i=1:high
for j=1:wide
if Itile(i,j)
I2(i,j)=255;
end
end
end
for i=1:num
for j=-i:i
I2(loc(i,1)+j,loc(i,2))=0;
I2(loc(i,1),loc(i,2)+j)=0;
end
end
imshow(I);
figure,imshow(I2);

toc
t=toc


Sample pictures:

blob.png

blob.png

Target tiles are marked with little plus in their centers.


This is the preliminary version of codes. Later, we realize the algorithm in various embedded system using opencv. 

My FDOROP project is maily about this topic, detailed information: http://104.131.150.53/thinkcmfx/index.php?g=&m=article&a=index&id=17