Image ROI Label Issue
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
itend
am 1 Sep. 2017
Kommentiert: itend
am 2 Sep. 2017
Hello,
I currently have a code which outputs images, I would like to label different ROI within these images using consecutive numbers. I have written some code to compute the centroid of the ROIs within the image that I would like to label, this data is stored in "props".
"props" is a 1 x 4 cell (I have 4 images, each cell corresponds to a different image). Each of the cells in "props" contains a 5 (the current images have 5 different ROI each) x 1 struct with 2 fields (Centroid Position and Mean Intensity). Here is the code I have thus far:
for i = i:length(props)
imagesc(boutput{1,i});
axis image
colormap('gray')
end
labelShiftX = -7; %simply for aligning number placement
for k = length(props{1})
cent = props{k}.Centroid;
text(cent(1) + labelShiftX, cent(2), num2str(k));
end
To note, "props" was generated using the regionprops function which takes in boutput and output, the binarized and original images, respectively.
So far, my code is not accomplishing the task and the ROIs within the image are not labeled. Any suggestions on how to proceed?
Thank you for your time and attention!!!!
2 Kommentare
Image Analyst
am 1 Sep. 2017
If props was generated by regionprops(), it's a structure array, not a cell array, and you'd use parentheses, not braces. Or it could be a table if you asked for a table. Please show the entire code.
Akzeptierte Antwort
Image Analyst
am 1 Sep. 2017
I think you need to extract out the props first. Try this:
thisProps = props{imageIndex}; % Extract props for this image only.
cent = thisProps(blobIndex).Centroid;
where imageIndex is the index (number) of the image you extracted from, and blobIndex is the index of the blob within that particular image. Be careful to use the braces and parentheses just like I did. So you need to decide which image you're working on and then within that image, what blob you're working on.
5 Kommentare
Image Analyst
am 2 Sep. 2017
Almost, but there is no guarantee that the number of blobs will equal the number of images. So you need to have the inner loop go to the number of blobs and change the index from k to i:
for k = 1:length(props)
thisProps = props{k};
for i = 1:length(thisProps)
cent = thisProps(i).Centroid;
text(cent(1) + labelShiftX, cent(2), num2str(i));
end
end
However, they will all be displayed on the currently displayed image, while the blobs were found on different images. So after you get thisProps you might want to display the k'th image, perhaps by calling figure() or subplot() and then imshow().
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!