How can I count the number of markers in a ROI after using impoly?

1 vue (au cours des 30 derniers jours)
Matthew Adams
Matthew Adams le 3 Juil 2015
Commenté : Image Analyst le 7 Juil 2015
I am working on a project where I need to count the number of markers within a drawn ROI on a .fig image using the impoly function. This .fig image is a MATLAB drawn representation of the original image and has already been generated from another code. In this image, there are plotted markers of different types (green squares and red circles) that represent different aspects of the original image.
Is there a simple way of doing this that I am just not getting? I am getting the error "Attempt to reference field of non-structure array" in regard to the "count_pa = BF_pa.NumObjects;" line. So far I have:
ROI_BF = 'MDA103L_tracingfig.fig';
openfig(ROI_BF); %Display image to determine number of masks needed
n = input('How many masks are needed?'); %Ask user for number of masks needed
for i=1:n
BF = impoly(gca); setColor(BF,'b'); %Draw polygon around Barrel Field (BF)
BF_pa = findobj(gca,'Color','r'); %find penetrating arteriole markers
count_pa = BF_pa.NumObjects;
BF_anast = findobj(gca,'Color','g'); %find anastomoses markers
count_anast = BF_anast.NumObjects;
end
end
Ultimately I would like to draw multiple ROIs and be able to count the numbers of green square and red circle markers in each ROI. I have attached the image that I use in the code. Also, I am using the R2013a version.

Réponses (1)

Image Analyst
Image Analyst le 3 Juil 2015
Change your other software so that BF_pa includes the x,y coordinates of all the colored spots. Then simply use inpolygon() to do the counting. If you don't get the x,y coordinates, it's much harder and maybe not 100% accurate because many of the spots overlap almost completely.
  2 commentaires
Matthew Adams
Matthew Adams le 6 Juil 2015
How would I try to get the x,y coordinates for all markers? I have tried to use the get function but so far I have been unsuccessful.
Also, I need to be able to draw the polygon because each image that I would analyze with this software will be slightly different. The inpolygon() function requires x and y coordinates for the polygon itself--how would I be able to store the coordinates of the drawn vertices to be used by inpolygon?
Image Analyst
Image Analyst le 7 Juil 2015
You drew the red spots on there so you must already know their coordinates.
You can use impoly() or roipoly() or roipolyold() to have the user indicate a polygon and get the vertex coordinates for them.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by