How do I tell matlab to identify vertices within ROI?
조회 수: 4 (최근 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!