matlab重要函数

####matlab重要函数

  • 图片读取
imgsrc=imread('imgdir/imgname.jpg');
  • 转灰度图
grayImg=rgb2gray(imgsrc);
  • 二值化
imgbin=imgsrc<120;
thresh=graythresh(imgsrc);
imgbin=im2bw(imgsrc,thresh);//0<thresh<1
imgbin=im2bw(imgsrc,0.63);
  • 显示图片
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);
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值