Prev: convert periodogram PSD estimation to signal amplitude
Next: An exact 1-D integration challenge - 66 - (sqrt, sin)
From: dale on 31 Jul 2010 21:54 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)
From: Walter Roberson on 31 Jul 2010 23:39 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)
From: dale on 1 Aug 2010 00:05 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
From: Image Analyst on 1 Aug 2010 00:16 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.
From: dale on 1 Aug 2010 00:32
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 |