Image ROI Label Issue

2 vues (au cours des 30 derniers jours)
itend
itend le 1 Sep 2017
Commenté : itend le 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 commentaires
Image Analyst
Image Analyst le 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.
itend
itend le 1 Sep 2017
Modifié(e) : itend le 1 Sep 2017
Here is the bit of code that generates props: props = cell(size(output,1),1);
for i = 1:size(output,2)
props{i} = regionprops(labelboutput{1,i},output{1,i},'MeanIntensity','Centroid');
end
What other parts of the code would you like to see? Thanks!

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 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 commentaires
Image Analyst
Image Analyst le 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().
itend
itend le 2 Sep 2017
Huzzah! That did the trick.
Like always, thank you so much for your advice and expertise!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by