Selecting data within a particular shape from a matrix.

1 回表示 (過去 30 日間)
waqas
waqas 2019 年 8 月 31 日
コメント済み: Matt J 2020 年 7 月 22 日
Hi,
I want to select data around point [169,547] in the attached v variable. Attached is the figure of the shape in which I want the coordinate values, their distance and angle with respect to the center point [169,547]. The case represents a dynamic crack which moves forward in the next frame and thus the center position will change in the next frame and the whole process will be repeated again. Any guidance regarding the implementation would be great.
Cheers
Waqas
  4 件のコメント
Image Analyst
Image Analyst 2019 年 8 月 31 日
His coordinate is probably (x, y) not (row, column), so the matrix should exist at row 169, column 547 in a matrix of 304 rows and 640 columns.
Matt J
Matt J 2020 年 7 月 22 日
waqas commented:
Hi,
I started a new question which is on the same lines as this question. It would be interesting to hear from you guys about that! I tried to figure it out by my own but am unable to get exactly what I want to.

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

採用された回答

Matt J
Matt J 2019 年 8 月 31 日
編集済み: Matt J 2019 年 8 月 31 日
As an example,
xc=547; yc=169; %center coordinates
rint=10; rext=50; %internal and external radii
[X,Y]=meshgrid((1:size(v,2))-xc, (1:size(v,1))-yc );
crack= Y<=rint & Y>=-rint & X<=sqrt(rint^2-Y.^2);
region= X.^2+Y.^2<=rext^2 & ~crack;
selected_data = v(region);
imshow(region);
  10 件のコメント
Matt J
Matt J 2019 年 10 月 7 日
編集済み: Matt J 2019 年 10 月 7 日
If you know the inclineAngle, it should be a 2-line modification,
[X,Y]=meshgrid((1:size(v,2))-xc, (1:size(v,1))-yc );
[Theta,Rho]=cart2pol(X,Y);
[X,Y]=pol2cart(Theta+inclineAngle, Rho);
crack= Y<=rint & Y>=-rint & X<=sqrt(rint^2-Y.^2);
region= X.^2+Y.^2<=rext^2 & ~crack;
selected_data = v(region);
imshow(region);
waqas
waqas 2019 年 10 月 7 日
編集済み: waqas 2019 年 10 月 7 日
Thank you so much for your input. It works perfectly. Just one correction, change the position of rho and theta in both cart2pol and pol2cart just in case someone comes across same problem in future.
Cheers,

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by