####matlab重要函数
imgsrc=imread('imgdir/imgname.jpg');
grayImg=rgb2gray(imgsrc);
imgbin=imgsrc<120;
thresh=graythresh(imgsrc);
imgbin=im2bw(imgsrc,thresh);//0
figure;imshow(imgsrc);title('imgsrc');
figure('Name','imgsrc');imshow(imgsrc);
imgsobel=edge(grayImg,'sobel');
se=strel('square',3);//Structuring element
imgdilate=imdilate(imgsobel,se);
imgerode=imerode(imgsobel,se);
imbwop=bwareaopen(imgdilate,300);
[L,num]=bwlabel(imbwop);
regionprops(L,'BoundingBox');//regionprops == get the properties of region
regionprops(L,'Centroid');
regionprops(L,'Area');
regionprops(L,'all');
for i=1:num
end
if area(i).Area>500 && status(i).BoundingBox(3)>30
'语句'
end
图像灰度x方向投影:
img_x=sum(f,2)/n;
plot(img_x,'r','LineWidth',1.5); %以序号为横坐标,img_x的值为纵坐标画出的折线
图像灰度y方向投影:
img_y=sum(f,1)/m;
plot(img_y,'r','LineWidth',1.5);
mesh(tu3);
A=[1 3 4 5 7 9]
diff(A)=[2,1,1,2,2];横向的间隔差值
####matlab 从txt中读取文件
clc;close all;clear all;
fin=fopen('/media/hhg/DWorkplace/2019-11-18/imglists.txt','r');
i=1;
while ~feof(fin)
str=fgetl(fin);
str2=strcat('/media/hhg/DWorkplace/2019-11-18/',str);
img=imread(str2);
imgGrey=rgb2gray(img);
% figure;imshow(imgGrey);
subplot(3,6,i);imshow(imgGrey);
imgroi1=imgGrey(116:1020,1254:1628);
imgroi2=imgGrey(116:1020,1628:1898);
% figure;imshow(imgroi1);
% figure;imshow(imgroi2);
imgroi1_bin=imgroi1>220;
imgroi2_bin=imgroi2>220;
subplot(3,6,i+6);imshow(imgroi1_bin);
subplot(3,6,i+6*2);imshow(imgroi2_bin);
% figure;imshow(imgroi1_bin);
% figure;imshow(imgroi2_bin);
% savepath1=strcat('/media/hhg/DWorkplace/2019-11-18/',int2str(i),'_roi1.jpg');
% savepath2=strcat('/media/hhg/DWorkplace/2019-11-18/',int2str(i),'_roi2.jpg');
% imwrite(imgroi1_bin,savepath1);
% imwrite(imgroi2_bin,savepath2);
i=i+1;
end
####matlab中读取cvs
fin=fopen('/home/hhg/Projects/SVN/upper_control/bin/filletHist.csv','r');
while ~feof(fin)
str=fgetl(fin); % 读取一行, str是字符串
temp=str2num(str);
figure;plot(temp>140);
end
fclose(fin);