what function contourc returns

3 views (last 30 days)
First of all I have to admit that I am not familiar with Matlab data structure. This is one of the reasons I am having a hard time to figure out the output of this contourc function.
Here is the code.
fm = double(imread('C:\data\01_01.bmp'));
c = contourc(fm,[.8 .8]);
01_01.bmp is a black and white image with an object in it. The returned c is 2X387 matrix. What kind of data does this matrix hold? It does not look like a sequence of pixel coordinates.
I searched the documentation, and it says that contourc is supposed to return a single contour at level 0.8 in this case. This is even more confusing. I am not familiar with this contour-at-level concept. Can someone explain what this contourc returns?

Accepted Answer

Patrick Kalita
Patrick Kalita on 10 Aug 2011
The contour matrix that contourc returns is basically a bunch of vertices that define the contour lines. Each vertex is an (x,y) pair and they are stored as columns in the contour matrix:
x1 x2 x3 ...
y1 y2 y3 ...
Except, there are also some columns in the matrix that hold information about how many vertices the contour line has and level (e.g. 0.8) of the contour. So the contour matrix might actually look something like this:
0.8 x1 x2 x3 ...
386 y1 y2 y3
The first column says that the next 386 columns are going to contain coordinates of a line at the contour level 0.8.
This documentation section explains the structure of the matrix in a little more detail.
  4 Comments
Xiaolei Hu
Xiaolei Hu on 10 Aug 2011
Another question that might relate the above one is How those coordinates are double instead of integers?
Patrick Kalita
Patrick Kalita on 10 Aug 2011
Contour lines are most often talked about in the context of functions of two variables (e.g. z = f(x,y)). A contour line is a line connecting points (x and y) on the surface that all have the same value for z.
The function can be applied to images, but it is more general than that and it relies on interpolation. That is why you get double-valued coordinates instead of integers.
More reading: http://en.wikipedia.org/wiki/Contour_line

Sign in to comment.

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!