How to find multiple minimum values in larger arrays?

6 views (last 30 days)
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
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.
Oliver
Oliver on 22 Oct 2014
Nope the 15 would still be a minimum as 7 of its surrounding grid points are smaller than itself. (It would be 8 surrounding grid points if the 20 was a larger value).
7 is in the required threshold of 6-8 surrounding grid points being 10 units larger.

Sign in to comment.

Accepted Answer

Matt J
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
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
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Images 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!