【问题标题】:Finding 2D contour area when contour contains edges of domain当轮廓包含域的边缘时查找二维轮廓区域
【发布时间】:2019-11-18 22:28:59
【问题描述】:

假设我们在 MATLAB 中有以下内容:

xs = -50:50;
ys = -50:50;
[X,Y] = meshgrid(xs,ys);
rs = (X.^2 + Y.^2).^(1/2);
c = contourf(X,Y,rs,[60,60]);

如何估算白色区域的面积?

这是一个测试用例,通常我不知道水平集的方程。

请注意,水平集与边界相交,我不能仅仅增加域大小来避免这种情况(在非测试用例中)。

【问题讨论】:

    标签: matlab area


    【解决方案1】:

    编辑:如果你想近似的白色区域也超出边界,那么下面的方法显然是行不通的。我刚刚意识到,您的措辞存在解释范围。


    如果您至少知道阈值轮廓级别(这里似乎是60),那么您可以计算低于该阈值的“像素”数量,并计算相对于x 和@987654323 的面积@。

    这是一些示例代码(我也修改了您的代码):

    x = -50:0.1:50;
    y = -50:0.1:50;
    [X, Y] = meshgrid(x, y);
    Z = (X.^2 + Y.^2).^(1/2);
    c = contourf(X, Y, Z, [60, 60]);
    colorbar();
    
    % Total amount of pixels representing the area
    a_pixels_total = length(x) * length(y)
    
    % Amount of pixels below given contour level
    a_pixels_below = sum(Z(:) <= 60)
    
    % Total area in units
    a_unit_total = (x(end) - x(1)) * (y(end) - y(1))
    
    % Percentage of area below the given contour level in units 
    a_unit_perc = a_pixels_below / a_pixels_total * a_unit_total
    

    那么输出是:

    a_pixels_total =  1002001
    a_pixels_perc =  952233
    a_unit_total =  10000
    a_unit_perc =  9503.3
    

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-09
      相关资源
      最近更新 更多