Getting meshgrid along different angles for data extraction from a matrix/image?
6 次查看(过去 30 天)
显示 更早的评论
Hi,
I have three point locations of a matrix which I want to use to get inclined meshgrid about the lines joining these points. I know how to individually perform these but I am unable to figure out how to rotate both of them together using pol2cart function. A similar question where pacman shape is obtained using the same technique. However, in the current implementation, I do not want a pacman shape and the rounded region that we see in the second plot should be at the end of the second line.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/334869/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/334869/image.jpeg)
How to resolve this?
x0 = 500; y0 = 1;
x1 = 450; y1 = 300;
x2 = 600; y2 = 700;
m = 1000; n=1500;
subplot(2,1,1)
plot([y0,y1,y2],[x0,x1,x2]); axis ij equal; xlim([1,n]);ylim([1,m]);
grid on;
title('This is how the lines should look in the image or matrix')
[yi,xi] = meshgrid(y1-(1:n),x1-(1:m));
ang = atan((y1-y0)/(x1-x0));
ang2 = atan((y2-y1)/(x2-x1));
[the,ro] = cart2pol(yi,xi);
tt = the(:,1:x1);rt = ro(:,1:x1);
[xt1,yt1] = pol2cart(tt+ang,rt);
tt2 = the(:,(x1+1):end);rt2 = ro(:,(x1+1):end);
[xt2,yt2] = pol2cart(tt2+ang2,rt2);
x = [xt1,xt2];
y = [yt1,yt2];
intR = 10; extR = 100;
subplot(2,1,2)
crack2 = x<=intR & x>=-intR & y<=sqrt(intR^2-x.^2);
notcrack= x<=(intR+extR) & x>=-(intR+extR) & y<=sqrt((intR+extR)^2-(x).^2);
region= notcrack & ~crack2;
imshow(region);h = gca; h.Visible = 'on';
title('this is the maximum external region')
2 个评论
Image Analyst
2020-7-22
I don't understand. What is an "inclined meshgrid"?
And do you have some mathematical/analytical formula for the mask and you just want to create a mask image(s) for some region(s) like a mask for crack and a mask for non-crack?
Then you say "I do not want a pacman shape". Well, I do not see such a shape in the images you posted, so I'm not sure why you said that.
Is your "maximal external region" image what you want, or not? It has no pacman shape. If it's not what you want, then what do you want?
Then you say "the rounded region that we see in the second plot should be at the end of the second line." Well, I do not see a second plot. Just one plot and a binary image. Do you want the U-shaped region in the left of the image to somehow be on your graph of the two line segments in the plot? I don't understand what that would look like so please show us.
采纳的回答
Matt J
2020-7-22
If you're just trying to generate shaded polygons, it would be simpler just to use impoly, e.g.,
x0 = 1; y0=1;
x1 = 200; y1=500;
x2 = 500; y2=100;
m = 800; n=600;
xy=[x0,y0;x1 y1;x2 y2];
xy=[xy;flipud(xy+[0,100])];
H=impoly(ancestor(imshow(false(m,n)),'axes'),xy);
imshow(H.createMask)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/335664/image.png)
14 个评论
Matt J
2020-7-26
I may be missing something, but it seems to me it would just be,
xt1 = xt1 + translation_vector(1);
yt1 = yt1 + translation_vector(2);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!