找到3D网格所有内部边缘坐标的最有效方法是什么?

时间:2017-05-17 23:05:30

标签: matlab image-processing multidimensional-array edges

我需要找到图像所有内部边缘的坐标。我试图通过以下程序实现这一目标:

  1. 使用0.5
  2. 的像素大小生成网格
  3. 获取所有顶点的坐标。
  4. 删除所有不需要的行:
    • 包含所有整数值的行
    • 包含2个非整数的行
    • 包含所有非整数的行
  5. 使用1像素的网格大小重新采样网格。
  6. 我觉得用像素间距1对网格进行重新采样会让我得到step 3中获得的坐标作为边的坐标。
  7. 代码如下:

    % input image
    Ydim = 3;
    Xdim = 3;
    Zdim = 3;
    
    
    % generate 3D mesh using a pixel spacing of 0.5
    [xgv, ygv, zgv] = meshgrid(1:0.5:Xdim - 1, 1:0.5:Ydim - 1, 1:0.5:Zdim - 1);
    
    % obtain coordinates of all internal vertices and edges
    allCoords = [ygv(:), xgv(:), zgv(:)];
    
    % Obtain only the coordinates of edges by keeping only two integers and one
    % non-integer in each row
    edgeCoords = allCoords;
    edgeCoords((sum(mod(allCoords,1)~=0, 2))~=1, :) = [];
    
    
    % re-sample 3D grid using a pixel spacing of 1
    [columnsInImage, rowsInImage, pagesInImage] = meshgrid(1:Xdim - 1, 1:Ydim - 1, 1:Zdim - 1);
    
    
    % plot points 
    plot3(edgeCoords(:,2), edgeCoords(:,1), edgeCoords(:,3), '.b', 'markersize', 20)
    hold on;
    grid on;
    
    scatter3(edgeCoords(:,1), edgeCoords(:,2), edgeCoords(:,3));
    

    我不完全确定上述5)中的假设以及整个程序。因此,我需要有人帮助我看看这个。我的假设是否正确?有没有更有效的方法来做到这一点?

    最后,我希望能够比我在代码中更好地想象这一点。谢谢你的帮助!

0 个答案:

没有答案
相关问题