Regionprops returns NaN as centroid value for a Label

Hi This I encountered while trying to relabel my labeling matrices for each of the 97 images I have. My Image Labels as got from below command: unique(filteredimagelabels{19}.L(filteredimagelabels{19}.L~=0)) % Here 19 number is my Image No.19
ans =
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
21
22
Total number of labels present in this Label matrix, as in the below command: length(unique(filteredimagelabels{19}.L(filteredimagelabels{19}.L~=0)))
ans =
21
After I applied region props, to the above Label matrix to generate new centroids and other properties, as in the below command:
testforimage19=regionprops(filteredimagelabels{19}.L,{'Centroid','Pixelidxlist'});
The number of fields I am getting in my testforimage19 are 22 (to the expected 21).
I checked my Centroid values for each of the fields in the testforimage19, turns out to be that: testforimage19(16).Centroid % 16 is ofcourse the ROI/Label in Image 19
ans =
NaN NaN
and, I also tried to get Pixel-ids (indices of label 16, for which Centroids were NaN, as seen above)
testforimage19(16).PixelIdxList
ans =
Empty matrix: 0-by-1
What mistake am I doing? I need some inputs. If not clear, shall try to explain more.
Thanks in advance
Harish

 Accepted Answer

Why/how are you filtering before calling regionprops? Why did blob #16 get removed? It gives results based on the label number, and since you didn't pass it a blob labeled 16, what would you expect it to pass back for that blob number? The only thing it could do is pass back something like null or nan. Yes, this is confusing but you brought it upon yourself when you passed it a labeled image with one of the labels missing. Normally one passes in a labeled image with all the labels there and you do the filtering AFTER calling regionprops, not before like you did it. Explain why you are filtering before, because this is why #16 got removed in image #19.

7 Comments

Hi
Thanks for the input. Yes, I agree. It makes sense. Now, I can explain this missing blob # 16 (in Image 19) over its previous image # 18. It means that, ROI 16 as in Image 18 is no more present in Image 19. My final task is that, I want to superimpose numbers on my ROIs over my images. The numbering has to be consistent in that, i.e., rest of the ROIs from say 17-22 in image 19 should be numbered the same as that of Image 18. I am also using Pixelidxlist property to be computed in my regionprops function. So, how to overcome this non-existent ROI #16 in Image 19? Should I just set the regionprops output (here testimage19) to zero and proceed to text(...over my image)?
Any suggestions/inputs are helpful.
Thank you very much again
Harish
The labeling functions work in 3D you know. So why aren't you doing that if you have blobs that are weird shapes and some come and go?
Can you elaborate your suggestion? I am glad that you grasped the scenarios in my task of blobs having weird shapes and appearing on and off across my image time-sequence.
I don't know what your images are but let's pretend that they are seeds in a watermelon and that you have a CT image of it. So you have, say, 100 2D slice images. Now if you look at one slice you will have some seeds and be missing some, and as you progress along slice by slice some seeds will appear while others will disappear. Rather than counting the seeds in each 2D slice and trying to keep track of which are the same and which are coming and which are going, you can just label the entire volume as one single 3D image instead of doing it a slice at a time over 100 slices. Does that explain it?
My images are cells (blobs) over a time-sequence. I have hundreds of images to be processed, I shall try to give the scenarios in my images. I have these contexts:
1. Some cells may die after some time from Time 1.
2. Some cells may divide to form new cells (new ROIs) over time.
3. Some cells may be appearing on and off at some time steps.
4. some cells may disappear randomly forever from some time point.
5. Some cells may change their shape and size.
Should I be using 'bwlabeln', since from my preliminary search of image analysis functions, that seems to have some N-dimensional capability.
Thank you
Harish
PS: I am using bwconncomp, labelmatrix, regionprops with Properties: Centroids and Pixelidxlist. It's a pain for me that, I have to keep track of these scenarios and one logical scenario miss in my code is giving me weird results.
I would. So do other people who do motion tracking and prediction - just look in VisionBib.
Looks like a ton of conceptual information is in there.
Thanks for your time, once again.
Harish

Sign in to comment.

More Answers (1)

The regionprops function tries searching for the component with label 16, which you seem to have filtered out. So, this component doesn't exist. So, whats the centroid of a component that has no pixels in it or is non-existant?
NaN seems like a good answer to me.

Community Treasure Hunt

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

Start Hunting!