How to identify contiguous regions between two thresholds?

13 ビュー (過去 30 日間)
K E
K E 2013 年 2 月 6 日
If I have a variable z at mapped locations x and y, is there way to obtain the x-y locations of the contour(s) enclosing any continuous region in which z is between two thresholds minZ and maxZ? I do not have the Image Processing toolbox but this task may be similar to image segmentation. Below I use contourf to obtain the x,y locations of the region's outer edge, but perhaps there is a better approach.
% Make a fake dataset
z = peaks;
z = z(1:25, :); % Let's make different numbers of x and y elements for clarity
y = 1:size(z, 1);
x = 1:size(z, 2);
% Desired thresholds for the region
minZ = 2;
maxZ = 3;
[cc, hh] = contourf('v6', x, y, z, [minZ maxZ]); % Must use version 6
for iContour = 1:length(hh)
% Obtain the x and y location of the region's outer edges
% Does not account for cutouts inside the region
if get(hh(iContour), 'cdata') == minZ
xOutline = get(hh(iContour), 'xdata');
yOutline = get(hh(iContour), 'ydata');
% Find the points inside the region
isInside = inpolygon(x, y, xOutline, yOutline);
end
end
delete(hh); % Get rid of contours

採用された回答

ChristianW
ChristianW 2013 年 2 月 6 日
編集済み: ChristianW 2013 年 2 月 6 日
[C,h] = contour(...)
The ContourMatrix C contains directly the infomation you are looking for. Just look up ContourMatrix in the Matlab help.
Here is an example plot for the first line:
Z = peaks;
subplot(211)
[C,h] = contour(Z,[2 3]); title('contour'); ax_c = gca;
subplot(212)
hold on; title('proof')
plot( C(1,(1:C(2,1))+1) , C(2,(1:C(2,1))+1) )
set(gca,'xlim',get(ax_c,'xlim'),'ylim',get(ax_c,'ylim'))
  1 件のコメント
K E
K E 2013 年 2 月 7 日
Great, now I not dependent on the v6 version of contour. Thanks!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 2 月 6 日
Explain what "identify" means. You can of course just make a binary image of where that criteria is true like this:
zIsInRange = (z >= minZ) & (z <= maxZ);
But this binary image could have several blobs on it. That's why I ask you what "identify" means to you. Normally if you had the Image Processing Toolbox, you'd call bwlabel() or bwconncomp().
  3 件のコメント
Image Analyst
Image Analyst 2013 年 2 月 6 日
Too bad you don't have the IPT. There are several ways to do this in a line or two, like with bwboundaries(), which will give you the nested/child boundaries also. I haven't played with contour() that much - it might be able to do it.
K E
K E 2013 年 2 月 6 日
Yes, I can do what I want with the 'v6' version of contourf. But that doesn't seem so stable!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by