Issue with regionprops returning no variable
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Image Analyst
il 13 Gen 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.
Più risposte (1)
Walter Roberson
il 13 Gen 2012
regionprops() will return no data if there are no non-zero entries in the matrix that is passed to it.
Vedere anche
Categorie
Scopri di più su Surfaces, Volumes, and Polygons in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!