Image ROI Label Issue

2 Ansichten (letzte 30 Tage)
itend
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
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.
itend
itend am 1 Sep. 2017
Bearbeitet: itend am 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!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by