How to find multiple minimum values in larger arrays?
6 views (last 30 days)
Show older comments
I work with larger arrays (100x100) and am trying to develop a script which finds minimum values in the array, 10 units smaller than the surrounding 6-8 grid points. For example in the followig array it would be the '15' and the '18'
30 30 30 29 30
30 30 30 15 20
30 30 30 30 30
30 18 30 30 30
30 30 30 30 30
Thing I am trying to achieve from the script:
- something which identifies minima in the array (10 units smaller than surrounding 6-8 grid points)
- a script which displays the location of where these minima are in the command window
My attempt at script was this (it doesn't run, doesn't display the location of the minima, but hopefully gives you an indication of what I'm looking for:
A=[25,26,25,25,26;27,25,25,23,23;25,26,22,4,20;25,25,25,20,25;26,26,25,...
25,26;25,25,25,26,25;24,25,24,25,26]
contourf(A,10,'LineColor','none')
%
for i=1:6; j=1:6;
if A(i,:)<=A(i+1,:)&& A(j,:)<=A(j+1,:)
disp(‘minima Present')
end
end
Any help with any part of the script would be greatly appreciated. Thanks :)
2 Comments
Matt J
on 17 Oct 2014
For example in the followig array it would be the '15' and the '18'
In your example, the '15' is neighbored by a '20'. is that a typo? If not, the 15 is not 10 units deep, as you require.
Accepted Answer
Matt J
on 17 Oct 2014
Edited: Matt J
on 17 Oct 2014
Here is the bulk of it, assuming you have the Image Processing Toolbox.
A =
30 30 30 29 30
30 30 30 15 30
30 30 30 30 30
30 18 30 30 30
30 30 30 30 30
>> imregionalmin(imhmin(A,10)).*A
ans =
0 0 0 0 0
0 0 0 15 0
0 0 0 0 0
0 18 0 0 0
0 0 0 0 0
3 Comments
Mohammad Abouali
on 17 Oct 2014
if
B=imregionalmin(imhmin(A,10)).*A
find the location like this
[r,c]=find(B>0);
r and c are the row and column
Matt J
on 17 Oct 2014
Edited: Matt J
on 17 Oct 2014
Is there a way of indexing this in the command window? e.g. if not equal to zero, it shows their locations.
The FIND command will do that.
Also I presume there is not way of getting around the 6-8 surrounding boxes, just has to be all eight?
There are additional arguments that can be passed to imhmin and imregionalmin to specify either 4-connectivity, or 8-connectivity (see their doc pages). I've never heard of 6-connectivity, and can't picture what it means, unless you're working with 3D images.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!