利用matlab将输入的rgb图像转化为灰度图像后,利用阈值求的二值图像,边缘算子求的边缘图像,边缘图像求归一化不变矩,

  • 虫虫123456
    了解作者
  • matlab
    开发工具
  • 955B
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 5 积分
    下载积分
  • 0
    下载次数
  • 2022-06-14 20:01
    上传日期
利用matlab将输入的rgb图像转化为灰度图像后,利用阈值求的二值图像,边缘算子求的边缘图像,边缘图像求归一化不变矩,
23894573moments.rar
  • moments.m
    2.3KB
内容介绍
function im=moments(picname) %myedge 函数文件,将图片进行求边缘计算输入图片的归一化矩 % im输出为计算所得矩 % picname为输入图片文件名 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %用sobel算子求取图像边缘 % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %转化灰度图像 I9=imread(picname); if ndims(I9)==3 I8=rgb2gray(I9) end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %取矩形区域 I0(:,:)=I8(1:440,20:600); subplot(121),imshow(I0),xlabel('a的图像'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %二值化图像 J=find(I0<120); I0(J)=0; J=find(120<=I0); I0(J)=255; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %选取最外部连通区域,用sobel算子提取最外部轮廓 I2 = bwareaopen(I0, 150000); I2=edge(I2,'sobel'); I2=~I2; imwrite(I2,'nihao.jpg') subplot(122),imshow(I2),xlabel('b的图像'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %计算I1七个不变矩 %(1)计算I1的而质心 %(2)计算各阶中心矩 %(3)计算不变中心矩的值 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I1=I2; I1=double(I1); [M,N]=size(I1); [x,y]=meshgrid(1:M,1:N); x=x(:); y=y(:); I1=I1(:); m00=sum(I1); m10=sum(x.* I1); m01=sum(y.* I1); xcenter=m10/m00; ycenter=m01/m00; % 计算归一化的各阶中心矩,具有平移不变性和伸缩不变性 cm00=m00; cm02=sum((y-ycenter).^2.*I1)/(m00^2); cm11=sum((x-xcenter).*(y-ycenter).*I1)/(m00^2); cm12=sum((x-xcenter).*(y-ycenter).^2.*I1)/(m00^2.5); cm21=sum((x-xcenter).^2.*(y-ycenter).*I1)/(m00^2.5); cm03=sum((y-ycenter).^3.*I1)/(m00^2.5); cm30=sum((x-xcenter).^3.*I1)/(m00^2.5); cm20=sum((x-xcenter).^2.*I1)/(m00^2); %计算七个不变矩 im(1)=log(abs(cm20+cm02)) im(2)=log(abs((cm20-cm02)^2+4*cm11^2)) im(3)=log(abs((cm30-3*cm12)^2+(3*cm21-cm03)^2)) im(4)=log(abs((cm30+cm12)^2+(cm21+cm03)^2)) im(5)=log(abs((cm30-3*cm12)*(cm30+cm12)*((cm30+cm12)^2-3*(cm21+cm03)^2)+(3*cm21-cm03)*(cm21+cm03)*(3*(cm30+cm12)^2-(cm21+cm03)^2))) im(6)=log(abs((cm20-cm02)*((cm30+cm12)^2-(cm21+cm03)^2)+4*cm11*(cm30-cm12)*(cm21+cm03))) im(7)=log(abs((3*cm21-cm02)*(cm21+cm30)*((cm30+cm12)^2-3*(cm21+cm03)^2)-(cm30-3*cm12)*(cm21+cm03)*(3*(cm30+cm12)^2-(cm21+cm03)^2)))
评论
    相关推荐