matlab - Get matrix statistics ignoring internal matrix -
i have image. have sliding window going across image , sliding window has "frame". both window , frame defined rectangles [x y w h]. know window contained within frame (may share edge), can't assume location. need get, example, standard deviation of in frame only.
for sake of visualization, assume have window (alpha characters) , frame (numeric characters). have [x y w h] defining each of them. know window in frame. how stdev of numeric characters?
1 8 3 8 2 0
a b c 5 2 8
c b 3 9 9
a c b 0 5 2
9 6 8 3 4 1
note: in reality piece of image numeric. used alpha characters distinguish window frame.
if know row , column range of window within frame, logical indexing 1 approach. self-contained example:
framesize = [5, 6]; % outer [width, height] of frame windowsize = [3, 3]; % [width, height] of window windowlocation = [2, 1];% [row, column] of top left element of window windowrowrange = windowlocation(1):(windowlocation(1)+windowsize(1)-1); windowcolrange = windowlocation(2):(windowlocation(2)+windowsize(2)-1); % generate example data: make 'frame' numbers negative frame = unifrnd(0,1,framesize); frame(windowrowrange, windowcolrange) = unifrnd(-1,0,windowsize); disp('frame:'); disp(frame); % generate logical indexes 'inside window' insidewindow = zeros(framesize); insidewindow(windowrowrange, windowcolrange) = 1; % take standard deviation of outer frame std(frame(~insidewindow));
outputs:
frame: 0.9961 0.0046 0.3998 0.1818 0.5797 0.3510 -0.8767 -0.5827 -0.0552 0.2638 0.5499 0.5132 -0.8161 -0.9503 -0.5091 0.1455 0.1450 0.4018 -0.7600 -0.0973 -0.5107 0.1361 0.8530 0.0760 0.9619 0.0844 0.9106 0.8693 0.6221 0.2399 std: 0.3234
the actual numbers different, have not seeded random number generation.
Comments
Post a Comment