How do I tell matlab to identify vertices within ROI?
2 次查看(过去 30 天)
显示 更早的评论
I want matlab to identify all vertices of the hexagons that will be within an ROI. That ROI can be of any shape (it can be an irregular shape).
Here is my code:
l=12;
k=14;
C=rand(l,k);
xhex=[0 1 2 2 1 0];
yhex=[2 3 2 1 0 1];
for i=1:k
j=i-1;
for q=1:l
m=q-1;
patch((xhex+mod(q,2))+2*j,yhex+2*m,C(q,i))
hold on
end
end
axis equal
h = drawfreehand;
I have attached a picture of a sample ROI.
I will appreciate any advise on this matter. Many thanks.
1 个评论
Image Analyst
2022-7-16
This would be so easy with a digital image. Just use h.createMask and bwmorph and find(). But using an analytical image created with patch or fill or whatever, it's trickier (at least for me).
回答(1 个)
VINAYAK LUHA
2024-1-7
编辑:VINAYAK LUHA
2024-1-8
Hi Mariam,
I understand that you're looking to identify the vertices of the hexagons that fall within the boundaries of a freehand-drawn ROI.
Follow the below steps to accomplish the above goal-
- Find vertices of the hexagons which are inside the ROI using the "inpolygon" function
- Next, eliminate the duplicate detections and show the vertices within the ROI.
Refer to the snippet below to see the MATLAB code to implement the above steps.
l = 12;
k = 14;
C = rand(l, k);
xhex = [0 1 2 2 1 0];
yhex = [2 3 2 1 0 1];
vertices = [];
for i = 1:k
j = i - 1;
for q = 1:l
m = q - 1;
x = (xhex + mod(q, 2)) + 2 * j;
y = yhex + 2 * m;
patch(x, y, C(q, i));
hold on
vertices = [vertices; [x', y']];
end
end
axis equal
% Let the user draw a freehand ROI
h = drawfreehand;
% Get the position of the ROI
roiPos = h.Position;
% Find which vertices are inside the ROI
inROI = inpolygon(vertices(:,1), vertices(:,2), roiPos(:,1), roiPos(:,2));
% Get the vertices that are inside the ROI
verticesInROI = vertices(inROI, :);
verticesInROI = unique(verticesInROI, 'rows', 'stable');
% Display the vertices within the ROI
disp('Vertices within the ROI:');
disp(verticesInROI);
For better understanding of the functions employed here, you might want to explore the provided documentation links.
Hope this answers your query.
Best regards,
Vinayak Luha
2 个评论
DGM
2024-1-8
It's step #1 in an itemized workflow, and it's shown plainly in the example code, yet there's demonstrably no point in creating a mask. It's not actually used for anything, because it's an artifact of a suggestion to use a different workflow based on raster images. I guess the AI picks up on red herrings like that and inserts decorations to satisfy the misdirection.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!