max and min of multiple cell arrays

  • Follow


hello guys,

Below is my code.

the variable 'fv' in the code outputs 2 cell arrays.

I would like to find the max and min of each of the arrays.

Help me if you can guys.

thanks
dale



%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear all;

Rs1 = [ 0 0 0 0 0 0 0 0 0 0 0 0;
           0 0 0 0 0 0 0 0 0 0 0 0;
           0 0 0 0 0 0 0 0 0 0 1 0;
           0 0 0 0 0 0 0 0 0 0 1 0;
           0 0 0 0 0 0 0 0 0 1 1 0;
           0 0 0 0 0 0 0 0 0 1 1 0;
           0 0 0 0 0 0 0 0 0 0 0 0;
           0 0 0 0 0 0 2 2 2 2 0 0;
           0 0 0 0 0 0 2 2 2 2 2 0;
           0 0 0 0 0 0 0 0 0 0 0 0;
           0 0 0 0 0 0 0 0 0 0 0 0;
           0 0 0 0 0 0 0 0 0 0 0 0]
       
       STATS = regionprops(Rs1, 'PixelList'  )
  

     fv=struct2cell(STATS)
0
Reply dale 8/1/2010 1:54:05 AM

dale wrote:
> hello guys,
> 
> Below is my code.
> 
> the variable 'fv' in the code outputs 2 cell arrays.
> 
> I would like to find the max and min of each of the arrays.
> 
> Help me if you can guys.
> 
> thanks
> dale
> 
> 
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%
> clc; clear all;
> 
> Rs1 = [ 0 0 0 0 0 0 0 0 0 0 0 0;
>           0 0 0 0 0 0 0 0 0 0 0 0;
>           0 0 0 0 0 0 0 0 0 0 1 0;
>           0 0 0 0 0 0 0 0 0 0 1 0;
>           0 0 0 0 0 0 0 0 0 1 1 0;
>           0 0 0 0 0 0 0 0 0 1 1 0;
>           0 0 0 0 0 0 0 0 0 0 0 0;
>           0 0 0 0 0 0 2 2 2 2 0 0;
>           0 0 0 0 0 0 2 2 2 2 2 0;
>           0 0 0 0 0 0 0 0 0 0 0 0;
>           0 0 0 0 0 0 0 0 0 0 0 0;
>           0 0 0 0 0 0 0 0 0 0 0 0]
>             STATS = regionprops(Rs1, 'PixelList'  )
>  
> 
>     fv=struct2cell(STATS)


ll1 = @(l) l(:);
l1 = @(l) max(ll1(l));
ll = @(l) min(ll1(l));
l1l = @(l) [l1(l), ll(l)];
cellfun(l1l, fv, 'Uniform', 0)
0
Reply Walter 8/1/2010 3:39:39 AM


thank you a lot Walter for the reply, but I'd like to ask you for just one more bit of help.


My 2 arrays are as follows as we know:

array_1=

    10     5
    10     6
    11     3
    11     4
    11     5
    11     6


array_2=

     7     8
     7     9
     8     8
     8     9
     9     8
     9     9
    10     8
    10     9
    11     9

The answer I wish to obtain is the Max and Min of  each column row in each of the 2 arrays  . To be clear, the answer,( i.e max and min column and row values) I want in the Variable Editor are as follows:

ans =

    11     6


ans =

    10     3


ans =

    11     9


ans =

     7     8

Appreciate it,
best,
dale
0
Reply dale 8/1/2010 4:05:24 AM

dale :

Do you know that you can get that info (the max and min coordinates of the blobs) directly from the STATS structure if you request BoundingBox?

 STATS = regionprops(Rs1, 'PixelList', 'BoundingBox' )
 for k = 1 : length(STATS)
     x1 = STATS(k).BoundingBox(1) + 0.5;
     x2 = x1 + STATS(k).BoundingBox(3) - 1;
     y1 = STATS(k).BoundingBox(2) + 0.5;
     y2 = y1 + STATS(k).BoundingBox(4) - 1;
     fprintf(1, 'BoundingBox for blob #%d: x1=%d, x2=%d, y1=%d, y2=%d\n', ...
         k, x1, x2, y1, y2);
 end

The reason you add the 0.5 is that the Bounding Box is OUTSIDE the pixels - in other words, it's on the edges of the pixels in between the pixel indexes.  So if you had a pixel at column 6 that was 0 and one at column 7 that was 1, the bounding box would be at "column" 6.5 since it's supposed to be totally outside the region.  Column 6 is the center of the pixel and so is column 7, so column 6.5 is the "edge" in between the pixels.  Just something to be aware of in case you thought bounding box was the outermost layer of the object or followed along the closest "0" layer containing the object perimeter.
0
Reply Image 8/1/2010 4:16:04 AM

thanks imageanalyst. appreciate the help guy. I tested it.
But when I have change the Rs1 matrix to include more blobs as follows:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear all;

Rs1 = [ 0,0,  0,  0, 0,  0, 0,  0, 0, 0,  0,  0;
    0,  0,  0,  0,  0,  0, 0,  0,  0,  0, 0, 0;
    0, 0,  0,  0,  3, 3, 3,  3, 3,  3,  0,  0;
    0, 0, 0,  0,  0,  0,  3, 3,  3,  0,  4, 0;
    0, 0, 0,  0,  0,  5,  0,  0, 0,  4,  4,  0;
    0,  0, 0,  0,  5, 5,  0,  0, 0,  4, 4, 0;
    0,0,  0,  0, 5, 5,  0,  0, 0,  4,  4, 0; 
    0,  0,  0, 0, 5,  0, 6,  6, 6,  0, 4,  0;
    0,  0, 0,  0, 0,  6,  6,  6,  6, 6,  0,  0;
    0,  0, 0,  0, 0, 0,   0,   0,  0, 0, 0, 0;
    0,  0,  0,  0,  0,  0,  0,  0, 0,  0,  0,  0;
    0,  0, 0,  0,  0,  0,  0,  0,0,  0,  0, 0]
     
     
      STATS = regionprops(Rs1, 'PixelList', 'BoundingBox' )
 for k = 1 : length(STATS)
     x1 = STATS(k).BoundingBox(1) + 0.5;
     x2 = x1 + STATS(k).BoundingBox(3) - 1;
     y1 = STATS(k).BoundingBox(2) + 0.5;
     y2 = y1 + STATS(k).BoundingBox(4) - 1;
     fprintf(1, 'BoundingBox for blob #%d: x1=%d, x2=%d, y1=%d, y2=%d\n', ...
         k, x1, x2, y1, y2);
 end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


the output is:


BoundingBox for blob #1: x1=1, x2=0, y1=1, y2=0
BoundingBox for blob #2: x1=1, x2=0, y1=1, y2=0
BoundingBox for blob #3: x1=5, x2=10, y1=3, y2=4
BoundingBox for blob #4: x1=10, x2=11, y1=4, y2=8
BoundingBox for blob #5: x1=5, x2=6, y1=5, y2=8
BoundingBox for blob #6: x1=6, x2=10, y1=8, y2=9


how I can get rid of the BoundingBox for blob#1 and blob#2 which is really non-existent blobs?

appreciate the help
thanks
ravi
0
Reply dale 8/1/2010 4:32:05 AM

dale wrote:

> The answer I wish to obtain is the Max and Min of  each column row in 
> each of the 2 arrays  .

The first function of the group I posted is the one that converts the 2D 
matrix into a column vector. If you replace that function with one that 
just returns its argument unchanged, then you would get column-wise min 
and max results.
0
Reply Walter 8/1/2010 7:28:40 AM

"dale "/ ravi:
The reason is that you didn't pass in the correct kind of labeled image into regionprops.  regionprops is supposed to take in a labeled image created by bwlabel, which will always start blob numbering at 1.  If you're going to not pass in a labeled image, but instead pass in some arbitrary image of your own creation, then I suggest you use Walter's method.
0
Reply Image 8/1/2010 2:36:03 PM

thanks guys.

dale aka ravi
0
Reply dale 8/1/2010 3:26:04 PM

7 Replies
694 Views

(page loaded in 0.223 seconds)

Similiar Articles:













7/23/2012 3:04:15 AM


Reply: