Selecting data within a particular shape from a matrix.

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 Commenti

The attached v variable is a matrix of size 304x640, so the coordinate [547,169] does not exist.
sorry it was otherway around. I mistakenly changed it. Edited the question.
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.
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.

Accedi per commentare.

 Risposta accettata

Matt J
Matt J il 31 Ago 2019
Modificato: Matt J il 31 Ago 2019
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 Commenti

It seems to work perfectly in this configuration. I am trying to flip the crack but am getting following shape with the changes in the code.
Moreover, eventually I want to extract the coordinates in the white region and convert them to polar coordinates with respect to initial point. Should I add xc and yc into the X and Y we are getting from the above code?
Annotation 2019-08-31 192841.png
To flip the crack:
crack= Y<=rint & Y>=-rint & X>=-sqrt(rint^2-Y.^2);
To get polar coordinates:
[rho,theta]=cart2pol(X(region), Y(region));
It does the job. Thanks a lot.
Just one added question, how to approach the problem if the slot ("crack" in the figure and code) is a little inclinded? For example, if the center point moves to another point to the left in the next frame and I want to keep to slot direction such that the slot would show the line direction from new center point to previous center point then how would indexing work in this case?
You would need to apply a coordinate rotation to the X and Y before generating the mask. This can be easily done by converting X,Y to polar coordinates. Or, you could use my AxelRot utility,
If the slotted shape is from an actual image that may vary from one snapshot to the next, rather than some theoretical computer graphics thing, then you'll have to use image analysis to find that slotted shape.
The data is infact coming from image analysis using digital image correlation but since the crack is not visible and the data is quite noisy so I am trying to validate the displacements using asymptotic series (william's solution). End goal is to get the crack tip accuratly. Attached is an image to give a better picture.
Annotation 2019-09-03 115617.png
I have been trying to generate the mask at titled angle but am unable to achieve that with the conversion to polar coordinates and then generating the mask. Is there an efficient way like above (in case of horizontal slit) where I can achieve the slit at inclind angle using a mask rather than hard coding the shape which would give me an error once I take greater outer region (external radius). Right now, the code works for any value of external radius because of masking and I would like to keep it that flexible.
I am attaching a case where the slit is more inclined thus making it hard for me to perform almost anything without generating significant error.
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 il 7 Ott 2019
Modificato: waqas il 7 Ott 2019
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,

Accedi per commentare.

Più risposte (0)

Richiesto:

il 31 Ago 2019

Commentato:

il 22 Lug 2020

Community Treasure Hunt

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

Start Hunting!

Translated by