You can solve this with a couple of modifications to a solution I posted to a related question. I used a section of the sample image mask in the question for data. First, you will need to fill the holes in the mask, which you can do using imfill from the the Image Processing Toolbox:x = 1:15; % X coordinates for pixelsy = 1:17; % Y coordinates for pixelsmask = imfill(data, 'holes');接下来,应用我的其他答案中的方法来计算轮廓坐标的有序集合(位于像素角上):Next, apply the method from my other answer to compute an ordered set of outline coordinates (positioned on the pixel corners):% Create raw triangulation data:[cx, cy] = meshgrid(x, y);xTri = bsxfun(@plus, [0; 1; 1; 0], cx(mask).');yTri = bsxfun(@plus, [0; 0; 1; 1], cy(mask).');V = [xTri(:) yTri(:)];F = reshape(bsxfun(@plus, [1; 2; 3; 1; 3; 4], 0:4:(4*nnz(mask)-4)), 3, []).';% Trim triangulation data:[V, ~, Vindex] = unique(V, 'rows');V = V-0.5;F = Vindex(F);% Create triangulation and find free edge coordinates:TR = triangulation(F, V);freeEdges = freeBoundary(TR).';xOutline = V(freeEdges(1, [1:end 1]), 1); % Ordered edge x coordinatesyOutline = V(freeEdges(1, [1:end 1]), 2); % Ordered edge y coordinates最后,您可以在像素边缘的中心处获得所需的坐标,如下所示:Finally, you can get the desired coordinates at the centers of the pixel edges like so:ex = xOutline(1:(end-1))+diff(xOutline)./2;ey = yOutline(1:(end-1))+diff(yOutline)./2;这是显示结果的图:imagesc(x, y, data);axis equalset(gca, 'XLim', [0.5 0.5+size(mask, 2)], 'YLim', [0.5 0.5+size(mask, 1)]);hold on;plot(ex([1:end 1]), ey([1:end 1]), 'r', 'LineWidth', 2);plot(ex, ey, 'k.', 'LineWidth', 2); 这篇关于在Matlab中的pcolor中找到轮廓/边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-11 22:25