Hello everyone. I have a matrix that contains a pairs (pixel coordinates), for example M = [51,2 ; 50,2 ; 50,3 ; 51,2 ; 50,2 ; 50,1 ; 51,2 ; 52,4 ; 50,3], size(M) 9x2. The idea is that these pixels models a curve/contour extracted by a picture.
My problem is to use linear interpolation to obtain a new set of pairs of pixel coordinates such that the curve/contour is divided evenly in X segments, let's suppose X=12 segments.
In the example I'll have that each segment has a length of 9/12=0.75, this means I need to save 12 pixels starting from the position (51,2), ending at (50,3) with a rest of 10 pixels inside this interval placed "equally" with a distance of 0.75 that follow the curve/contour.
It seems impossible to obtain, save and display this new set of points because MATLAB works only with integer values. Notice that after this step, I need to use the new set of pixel coordinates to implement other functionalities (I don't need to display them and stop).
Does anyone knows a possible solution to my problem? Are there any functions that allow to use decimal coordinates (like cartesian axis)?
Thank you so much in advance.

1 件のコメント

Jan
Jan 2017 年 1 月 19 日
I cannot imagine what "because MATLAB works only with integer values" means. Of course Matlab works with floating point values also. The coordinates can be floating point values without any problems. Only the indices of arrays must be integer, but this does not matter here at all. Do I understand correctly, that you want to obtain a [12 x 2] matrix by interpolation from your [9 x 2] matrix? If you claim, that the segements have a length of 0.75 - what does this mean? 0.75 in which units? I seems like you confuse the value of the elemts with the index.

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

 採用された回答

Jan
Jan 2017 年 1 月 19 日
編集済み: Jan 2017 年 1 月 19 日

0 投票

M = [51,2 ; 50,2 ; 50,3 ; 51,2 ; 50,2 ; 50,1 ; 51,2 ; 52,4 ; 50,3];
L = size(M, 1);
MM = interp1(1:L, M, linspace(1, L, 12));
This does not consider this part of your question:
In the example I'll have that each segment has a length of 9/12=0.75,
this means I need to save 12 pixels starting from the position (51,2),
ending at (50,3) with a rest of 10 pixels inside this interval placed
"equally" with a distance of 0.75 that follow the curve/contour.
because I do not understand its meaning.

4 件のコメント

Nicolas Perillo
Nicolas Perillo 2017 年 1 月 19 日
編集済み: Nicolas Perillo 2017 年 1 月 19 日
Thank you for your answer Jan Simon. Okay, I'll try to explain in a better way with the help of this picture.
As you can see, I have the skeleton of a line. I used the function "bwtraceboundary" to obtain a matrix M with the coordinates of each pixel.
Now I want to divide this line evenly into EXACTLY 200 points, but I don't know how to use interpolation.
I was thinking to create a new set of points (as you said, I want to obtain a new matrix from the matrix M) where there are stored ONLY the "intermediate pixels" (in red in the following picture). Each red pixel has a distance ß from the next one.
Notice that I used Paint to draw this example and it was a bit difficult to divide the line evenly. I used the length ß to make clear that the line is divided evenly.
So, in a few words, I want to obtain the matrix that contains the coordinates of red pixels.
Thank you very much.
Jan
Jan 2017 年 1 月 19 日
While the already posted linear intpolation does almost what you want, limiting the length beta exactly is not trivial, when the line is not straight. Do you want to approximate the distance assuming the line consists of piecewise straight lines? Or do you want to consider the curvature?
Nicolas Perillo
Nicolas Perillo 2017 年 1 月 19 日
Okay I got it. Anyway I think for my implementation it would be better to consider the curvature.
Nicolas Perillo
Nicolas Perillo 2017 年 1 月 19 日
I just had the occasion to try your 2 simple rows of code and I think I solved all my problems! Thank you, it works like a charm.

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

カテゴリ

ヘルプ センター および File ExchangeInterpolation of 2-D Selections in 3-D Grids についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by