Clear Filters
Clear Filters

How to detect a particular contour in a matlab plot?

4 views (last 30 days)
I'm trying to extract a particular outline from a matlab pcolor plot (generated from a Matrix named 'M' which is uploaded here as well) as shown in this image. Original Plot
However I would like to extract the contour only, as shown here. (The yellow color line is the one which I would like to extract and is highlighted here for illustration purpose) Required Plot
But I'm getting the result as the following. ( I don't require any other bits/clutter apart from the curve) Obtained Plot
I'm applying the following code on the Matrix M to obtain the in the erroneous result.
[~, threshold] = edge(M, 'sobel');
fudgeFactor = 0.6;
BWs = edge(M,'sobel', threshold * fudgeFactor);
se90 = strel('line',6,70);
se0 = strel('line',3,90);
BWsdil = imdilate(BWs, [se90 se0]);
BWnobord = imclearborder(BWsdil,18);
seD = strel('cube',3);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
pcolor(BWfinal);colormap(jet); shading interp;colorbar;
How to obtain only the contour as required? Do I have to use any edge detection filters or do I have to perform smoothing prior to applying any filters? Thanks for any pointers or suggestions to accomplish this.

Answers (1)

Walter Roberson
Walter Roberson on 1 Jun 2017
If you already know the [x y] path, then you could consider improfile() . Or just call interp2 directly, similar to https://www.mathworks.com/matlabcentral/answers/342101-how-do-you-get-an-arbitrary-1-dimensional-line-scan-from-a-2d-matrix#comment_457886
  2 Comments
Sachin Nag
Sachin Nag on 2 Jun 2017
I don't know the rows and columns or [x y] values. Is it possible in some way to do it by detecting the edges/contours or something similar?
Walter Roberson
Walter Roberson on 9 Jun 2017
It sounds to me as if you need something like envelope detection
However as you are working in 2D then perhaps what you should use is boundary() (requires R2014b or later; if you are using an earlier release look in the File Exchange for "active contours"

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!