获得imcontour函数每个轮廓坐标

程序如下:

clear;clc
I=imread('G:\桌面备份\2017.10.2备份\等高线\等高线程序备份\6.jpg'); 
img=rgb2gray(I);
[c,h] =imcontour(img);
% 等高线标注
h_clabel=clabel(c,h); 
set(h_clabel,'BackgroundColor',[1 1 .6])  
s = getcontourlines(c);

调用函数如下:

function s = getcontourlines(c)

    sz = size(c,2);     %# Size of the contour matrix c
    ii = 1;             %# Index to keep track of current location
    jj = 1;             %# Counter to keep track of # of contour lines

    while ii < sz       %# While we haven't exhausted the array
        n = c(2,ii);    %# How many points in this contour?
        s(jj).v = c(1,ii);        %# Value of the contour
        s(jj).x = c(1,ii+1:ii+n); %# X coordinates
        s(jj).y = c(2,ii+1:ii+n); %# Y coordinates
        ii = ii + n + 1;          %# Skip ahead to next contour line
        jj = jj + 1;              %# Increment number of contours
    end

end

其中,输出的s为一个结构体,存放每个一个像素值轮廓的坐标。上面函数同样适用于计算等高线的函数contourf。截图如下,其中v为像素值,x和y为对应的轮廓的横纵坐标。

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值