Issue with regionprops returning no variable

5 vues (au cours des 30 derniers jours)
Micheal
Micheal le 13 Jan 2012
I'm having trouble going through a for loop that's calculating a centroid location using the previous images centroid location as a selection point for the next to bwselect. I'm not sure why, but sometimes it will use the same points for a selection point, and get nothing appended to the centroids variable. The images I'm using are of a varying shaped tube, each image a section of tube. I'm attempting to find a line that passes through each centroid of each slice. imagedata is a cell array of the binary images of the pipe.
Here's my question: What's causing this hiccup? It's not an issue with rounding. The regionprops command simply isn't returning a value sometimes, and is others. It cycles through the correct number of times, but merely stops appending onto the centroids variable. Anyone have any suggestions?
[x,y,BW2,idx,xi,yi] = bwselect(~imagedata{n}, 4);
close gcf % closes selection window
centroids = [];
for i = n:p
clc
[x,y,imbw{i},idx,xi,yi] = bwselect(~imagedata{i},xi,yi,4); % uses prior centroid location and writes new centroid to variable
s{i} = regionprops(imbw{i},'centroid'); % necessary intermediary due to regionprops mechanics
centroids = cat(1,centroids,s{i}.Centroid); % appends new centroid to list of centroids
end

Réponse acceptée

Image Analyst
Image Analyst le 13 Jan 2012
You're not assigning the centroids to xi and yi. xi and yi are lists of all the x and y coordinates in the selected object(s), which is fine - they're just not centroids. But anyway . . . If the current slice was so far shifted that none of it overlapped the prior slice, not even a single pixel, then it would return nothing (no centroids). Like Walter, I suspect that is what is happening.
Unless you're storing imbw for some reason, there's no need for it to be a cell array. A 3D array would be simpler but that's not even needed. You could have it just be a 2D array that gets overwritten every time (unless for some reason you need to retain it after the loop exits).
You could always use imreconstruct() as an alternative to bwselect() if you want.
  2 commentaires
Micheal
Micheal le 13 Jan 2012
Hah! You're right. I designed the code to use the most recent centroid as the new bwselect selection, but didn't actually assign the new centroid to the next xi and yi. Solved the problem wonderfully now that I wasn't just using the same selection point over and over again. :)
Micheal
Micheal le 13 Jan 2012
And thanks. :)

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 13 Jan 2012
regionprops() will return no data if there are no non-zero entries in the matrix that is passed to it.
  1 commentaire
Micheal
Micheal le 13 Jan 2012
The problem with that is that the code uses the previous entry's location to select the new centroid. The next centroid will be close to the first one, so I'm confused why it's returning no data, especially since it's returning no data at different iteration points when run multiple times. Theoretically, no matter where I select the first point, all the other points will be the same, so it shouldn't stop at different locations.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Surfaces, Volumes, and Polygons dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by