MATLAB:如何从网格中制作二维二进制掩码?

时间:2015-03-14 16:14:20

标签: matlab mask mesh roi

我在Matlab中使用MESH2D 以便从图像中筛选出ROI(感兴趣区域)。现在我想用这些三角形网格制作二进制掩码。 [p,t] = mesh2d(节点)的输出为:

  • p = Nx2阵列的节点XY坐标。
  • t = Mx3三角形数组,表示为P,用逆时针节点排序定义。

初始代码的示例(随意改进它!):

    mask= logical([0 0 0 0 0; 0 1 1 0 0; 0 1 1 1 1; 0 1 1 0 0]) %let's say this is my ROI
    figure, imagesc(mask)
    lol=regionprops(mask,'all')
    [p,t] = mesh2d(lol.ConvexHull); %it should mesh the ROI

如何从这个三角形网格制作面具? 先感谢您!

这是p:

    1,50000000000000    2
    1,50000000000000    2,50000000000000
    1,50000000000000    3
    1,50000000000000    3,50000000000000
    1,50000000000000    4
    1,93703949778653    2,56171771423604
    1,96936200278303    3,98632617574682
    2   1,50000000000000
    2   4,50000000000000
    2,00975325040940    3,53647067507122
    2,01137717786904    2,05700769275495
    2,05400996239344    3,03376821385856
    2,41193753423879    2,49774899749798
            2,45957145752038    3,46313210038859
    2,50000000000000    1,50000000000000
    2,50000000000000    4,50000000000000
    2,51246316199066    3,99053096338726
    2,56500321259084    1,97186739050944
    2,64423955240966    2,98576823004855
    3   1,50000000000000
    3   4,50000000000000
            3,00248771086621    2,47385860181019
    3,01650848812758    3,52665319517610
    3,08981230082503    3,98949609178151
    3,12731558449295    2,02370031640169
    3,36937385842331    2,99811446160210
    3,50000000000000    1,75000000000000
    3,50000000000000    4,25000000000000
    3,85193739480358    3,46578962137238
    3,85353024582881    2,53499308989903
    4   2
    4   4
    4,42246720814684    3,00037409439956
    4,50000000000000    2,25000000000000
    4,50000000000000    3,75000000000000
    4,97304775909580    2,99999314296989
    5   2,50000000000000
    5   3,50000000000000
    5,50000000000000    3

和t:

    9   5   7
    20  18  15
    1   8   11
    8   15  11
    11  15  18
    11  2   1
    6   2   11
    20  27  25
    25  18  20
    27  30  25
    17  10  14
    7   10  17
    24  21  17
    9   7   17
    29  35  32
    26  30  29
    23  19  26
    14  19  23
    26  29  23
    23  29  24
    23  17  14
    24  17  23
    6   11  13
    13  11  18
    34  30  31
    31  30  27
    3   2   6
    12  19  14
    14  10  12
    6   13  12
    12  13  19
    12  3   6
    28  21  24
    28  29  32
    24  29  28
    9   17  16
    16  17  21
    38  35  33
    35  29  33
    33  29  30
    34  37  33
    33  30  34
    19  13  22
    26  19  22
    18  25  22
    22  13  18
    22  30  26
    22  25  30
    4   7   5
    4   10  7
    4   12  10
    3   12  4
    38  33  36
    36  33  37
    39  38  36
    36  37  39        

1 个答案:

答案 0 :(得分:1)

要获取ix三角形的蒙版,请使用:

poly2mask(p(t(ix,:),1),p(t(ix,:),2),width,height)

t用于索引n以获取一个三角形的数据。