How to assign different color for different classes in object detection model?
Mostrar comentarios más antiguos
Greetings, I have two classes, which are labelled as normal and cancer cells. How to draw bounding boxes with different colors that referred to each class?
newp2 = imread([pathname filename]);
[bboxes,scores,labels] = detect(detector,newp2,'Threshold',0.7);
annotations = string(labels) + ": " + string(scores);
I = insertObjectAnnotation(newp2,'rectangle',bboxes,cellstr(annotations));
figure
imshow(I)
Respuestas (1)
Sachin
el 13 de Abr. de 2023
Hi
I understand that you want to assign the different color for different classes in object detection model.
To draw bounding boxes with different colors for each class, you can modify the ‘Color’ parameter based on the class label,
Here is an example:
newp2 = imread([pathname filename]);
[bboxes,scores,labels] = detect(detector,newp2,'Threshold',0.7);
annotations = string(labels) + ": " + string(scores);
%loop through each detected object
for i=1:numel(bboxes)
label = labels(i);
bbox = bboxes(i,:);
score = scores(i);
if label=='inormal'
color = 'b'
elseif label == 'cancer'
color = 'r'
else
color = 'g'
insertObjectAnnotation(newp2,'rectangle',bboxes,cellstr(annotations),'Color',color);
end
Please refer the following page for more information about ‘insertobjectannotation’
5 comentarios
Fahmi Akmal Dzulkifli
el 13 de Abr. de 2023
Sachin
el 13 de Abr. de 2023
Ok Then just try finding the number of rows in bboxes in this case 219. So replace the numel with number of rows
Fahmi Akmal Dzulkifli
el 13 de Abr. de 2023
Sachin
el 22 de Abr. de 2023
Hi
Can you please tell what kind of error you are getting?
Fahmi Akmal Dzulkifli
el 28 de Abr. de 2023
Categorías
Más información sobre Simulink Check en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!