# How do I tell matlab to identify vertices within ROI?

4 vues (au cours des 30 derniers jours)
Mariam Shahab le 16 Juil 2022
Commenté : VINAYAK LUHA le 8 Jan 2024
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 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Image Analyst le 16 Juil 2022
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).

Connectez-vous pour commenter.

### Réponses (1)

VINAYAK LUHA le 7 Jan 2024
Modifié(e) : VINAYAK LUHA le 8 Jan 2024
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.
Best regards,
Vinayak Luha
##### 2 commentairesAfficher AucuneMasquer Aucune
DGM le 8 Jan 2024
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.
VINAYAK LUHA le 8 Jan 2024
Thank you for highlighting that, @DGM

Connectez-vous pour commenter.

### Catégories

En savoir plus sur ROI-Based Processing dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by