How to use the find function against regionprops?
2 views (last 30 days)
Show older comments
Hi there, I''m having trouble using the find function.. Basically, I have this image called binaryImage, I want to find specific areas of the image with a range of parameters. Here's my code:
Lh=bwlabel(binaryImage,8);
blobMeasurements = regionprops(Lh, I, 'all');
And a whole bunch of codes(not included here) that allow me to display in Matlab, a few parameters of the labeled areas(blobs):
Blob # Mean Intensity Area Diameter Eccentricity
# 1 196.6 4393.0 74.8 0.6
# 2 234.1 55.0 8.4 0.9
# 3 242.9 9.0 3.4 0.9
# 4 216.2 316.0 20.1 1.0
# 5 232.7 49.0 7.9 1.0
.
.
.
para1 = [blobMeasurements.Eccentricity];
para2 = [blobMeasurements.MeanIntensity];
Keeper_Indexes = find(0.9<para1<=0.1 & 230<para2<250);
PossibleCracks = ismember(Lh, Keeper_Indexes);
figure, imshow(PossibleCracks, 'DisplayRange', []), title('Possible Cracks');
I thought it would show me the areas of blobs#2, #3, and #5, but figure 'Possible Cracks' doesn't show me that.. instead it shows me alot of unnessary other blob areas. What should i do? Please advice! Thank you!
0 Comments
Accepted Answer
Walter Roberson
on 27 Dec 2012
When you have
A<B<C
then MATLAB interprets that as
((A<B)<C)
The result of (A<B) is a logical vector of 0's and 1's. If C is all 0's then the result would be false; if C is all greater than 1, then the result would be true; if C contains some 1's then it is possible to get a mix of true and false results out.
In the case of your 0.9<para1<=0.1 you are testing (0's and 1's) <= 0.1 which will be true for the 0's and false for the 1's, and so would be equivalent to just testing
0.9 >= para1
In the case of your 230<para2<250 you are testing (0's and 1's) < 250 which will always be true.
If you want to test a range, then use
(lowvalue < x) & (x < highvalue)
but adjusting the < to <= if appropriate.
Notice that in 0.9<para1<=0.1 that you are not going to be able to find any values that are less than 0.9 but simultaneously less than 0.1 . You should recheck what you want for that condition and rewrite it in the (lowvalue < x) & (x < highvalue) format.
3 Comments
Image Analyst
on 2 Jan 2013
Alternatively,
rgbImage = cat(3, grayImage, grayImage, grayImage);
More Answers (0)
See Also
Categories
Find more on Geometric Transformation and Image Registration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!