get the matrix values under a line

6 ビュー (過去 30 日間)
Armindo
Armindo 2015 年 10 月 11 日
コメント済み: Rahand Dalshad 2021 年 5 月 2 日
Hi,
I have a matrix of data (120x90) that I plot and then I draw a diagonal line by doing something like:
plot([x1,x2],[Y1,Y2],'g.');
I need to be abe to determine all the matrix values under the line. Any idea about how to perform this efficiently?

回答 (3 件)

Image Analyst
Image Analyst 2015 年 10 月 12 日
If you have the Image Processing Toolbox, you can get this information from the function improfile().
improfile(I,xi,yi,n) returns pixel intensity values, where n specifies the number of points to include.
c = improfile(___) returns the intensity values in c, an n-by-1 vector, if the input is a grayscale intensity image, or an n-by-1-by-3 array if the input is an RGB image.
[cx,cy,c] = improfile(I,xi,yi,n) additionally returns the spatial coordinates of the pixels, cx and cy, of length n.
  3 件のコメント
Image Analyst
Image Analyst 2015 年 10 月 13 日
You're welcome. Can you go ahead and "Accept this answer" then? Thanks!
Rahand Dalshad
Rahand Dalshad 2021 年 5 月 2 日
Dear Image Analyst,
I want to thank you personally for all your help, suggestions and solutions to Matlab issues and questions. Lately, I am doing much images post-processing of optical obtained images and data. Wherever I stuck and google for a proper solution, I find the best and easiest solution from you.
Thank you again and keep up the good work
Regards form Germany
Rahand

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


Star Strider
Star Strider 2015 年 10 月 11 日
You would have to define every (x,y) pair along the line, in terms of the row and column values of the matrix coordinates. That will likely be straightforward when you derive an equation for the line.
I am not certain what information you want from the matrix, but you might also consider using the interp2 function if you want to interpolate the values of the matrix.
  4 件のコメント
Armindo
Armindo 2015 年 10 月 12 日
Your are completly right. I did not explain myself properly and I apologize for that. I belive that your suggestion (about determine the intersections of the line with a grid of coordinates) would work perfectly I will give it a try. Thank you very much for the help and code.
Star Strider
Star Strider 2015 年 10 月 12 日
My pleasure.
I tested that code thoroughly so it should be robust. I’ll do my best to help you adapt it if necessary, but I wrote it years ago (and haven’t used it much since), so I’d have to remember what I did.

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


William Chamberlain
William Chamberlain 2018 年 10 月 17 日
  1 件のコメント
Image Analyst
Image Analyst 2018 年 10 月 17 日
Using improfile() with the 'nearest' option would also do that, if he wanted to go to the nearest pixel instead of doing subpixel interpolation.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by