MATLAB计算绘图上的形状区域

时间:2016-04-05 19:46:08

标签: matlab area

我使用imagesc创建一个图。 X / Y轴分别是经度和纬度。 Z值是下图所示图像的强度。我希望能够做的是计算每个显示的多边形的面积。任何人都可以推荐一种直接(或任何)方法来实现这一目标吗?

修改

忘记包含图片。

enter image description here

2 个答案:

答案 0 :(得分:1)

以下是玩具示例。它取决于假设Z值在对象内部与外部不同(此处:不是0)。此外,我在第4列假设一个直分隔线,但相同的原理(应用掩模)可以应用于其他边界。这也假设值在xy轴上是等距的,但问题并没有相反。如果不是这种情况,则需要使用bsxfun进行更多工作。

A = [0     2     0     0     0     2     0
     3     5     3     0     1     4     0
     1     4     0     0     3     2     3
     2     3     0     0     0     4     2
     0     2     6     0     1     6     1
     0     3     0     0     2     3     0
     0     0     0     0     0     0     0];

area_per_pix = 0.5; % or whatever

% plot it 
cm = parula(10);
cm(1, :) = [1 1 1];
figure(1);
clf
imagesc(A);
colormap(cm);

% divider
dv_idx = 4;

left_object = A(:, 1:(dv_idx-1));
left_mask = left_object > 0; % threshold object
num_pix_left = sum(left_mask(:));

% right object, different method
right_mask = repmat((1:size(A, 2)) > dv_idx, size(A, 1), 1);
right_mask = (A > 0) & right_mask;
num_pix_right = sum(right_mask(:));

fprintf('The left object is %.2f units large, the right one %.2f units.\n', ...
    num_pix_left * area_per_pix, num_pix_right * area_per_pix);

答案 1 :(得分:0)

这可能会有所帮助:http://se.mathworks.com/matlabcentral/answers/35501-surface-area-from-a-z-matrix 他没有使用过imagesc,但它也是一个类似的问题。