How to save X ,Y coordinates in a structure?
10 次查看(过去 30 天)
显示 更早的评论
Helo, I am looking for help.
I have an image I that has several different regions on it.
I calculated the weighted centroids and standard deviation of those regions. Then I want to extract X and Y coordinates of a region on a image that has the maximum standard deviation in that structure, but I am having troubles doing that.
I have done this so far
I calculated the Std:
s = regionprops(BW, I, {'WeightedCentroid','PixelValues');
for k = 1 : numObj
s(k).StandardDeviation = std(double(s(k).PixelValues)); #I calculated the std of these regions
end
Then I tried to get the max value od std in structure but no luck.
This is how I did it:
sStd = [s.StandardDeviation];
MaxStd = find(max(sStd));
imshow(I);
hold on;
for k = 1 : length(MaxStd)
rectangle('Position', s(MaxStd(k)).BoundingBox, ...
'EdgeColor','g');
end
hold off;
I hope that I was clear with the explanation. This maybe seems somehow trivial, but I just can not find the solution. Can anyone help me? Thanks in advance!
0 个评论
采纳的回答
Geoff Hayes
2015-2-11
Mario - if s(k).PixelValues) is a one dimensional array, then the standard deviation of this array will be a single element. Is this the case? If true, then
sStd = [s.StandardDeviation];
will be a one dimensional array, and the maximums standard deviation calculated as
MaxStd = max(sStd); % no need for the find
will be a scalar value. If you want to find which region has this maximum standard deviation, then just do instead
[MaxStd,RegionIdx] = max(sStd);
with
rectangle('Position', s(RegionIdx).BoundingBox, ...
'EdgeColor','g');
Try the above and see what happens!
Note that your code is assuming that MaxStd is an array, and then you try to access s with MaxStd(k) which is (most likely) a floating point number which will lead to the Subscript indices must either be real positive integers or logicals.
3 个评论
Geoff Hayes
2015-2-12
Mario - perhaps save the structure s to a mat file so that I can see what you about the PixelValues having different dimensions or are structures (?). Also, if you are now able to find the region with the largest standard deviation, given by the index RegionIdx, can't you use that to get the centroid of that region?
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!