📄 vmquantc.m
字号:
%%% if wi
%%% varg(vind) = (M1i * M1i') / wi;
%%% end
%%% M1diff = M1box - M1i;
%%% wdiff = wbox - wi;
%%% if wdiff
%%% varg(vind) = varg(vind) + (M1diff * M1diff') / wdiff;
%%% end
%%% end % for i (green)
%%% if isempty(varg)
%%% varg = -1;
%%% end
%%%
%%%% Find point of minimum variance in b dimension of box.
%%%
%%% M0base = sum( M0( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2)], [boxll(box,3) boxll(box,3)] ) ) - ...
%%% M0( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2)], [boxll(box,3) boxll(box,3)] ) ) );
%%% M1base = [sum( M1r( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2)], [boxll(box,3) boxll(box,3)] ) ) - ...
%%% M1r( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2)], [boxll(box,3) boxll(box,3)] ) ) ) ...
%%% sum( M1g( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2)], [boxll(box,3) boxll(box,3)] ) ) - ...
%%% M1g( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2)], [boxll(box,3) boxll(box,3)] ) ) ) ...
%%% sum( M1b( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2)], [boxll(box,3) boxll(box,3)] ) ) - ...
%%% M1b( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2)], [boxll(box,3) boxll(box,3)] ) ) )];
%%%
%%% varb = zeros(1,boxur(box,3)-boxll(box,3)-1); % Allocate space for the array.
%%% for i=boxll(box,3)+1:boxur(box,3)-1
%%% wi = M0base + ...
%%% sum( M0( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2)], [i i] ) ) - ...
%%% M0( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2)], [i i] ) ) );
%%% M1i = M1base + ...
%%% [sum( M1r( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2)], [i i] ) ) - ...
%%% M1r( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2)], [i i] ) ) ) ...
%%% sum( M1g( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2)], [i i] ) ) - ...
%%% M1g( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2)], [i i] ) ) ) ...
%%% sum( M1b( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2)], [i i] ) ) - ...
%%% M1b( elem3d( rgbsize, [boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2)], [i i] ) ) )];
%%% vind = i - boxll(box,3); % Inefficient.
%%% if wi
%%% varb(vind) = (M1i * M1i') / wi;
%%% end
%%% M1diff = M1box - M1i;
%%% wdiff = wbox - wi;
%%% if wdiff
%%% varb(vind) = varb(vind) + (M1diff * M1diff') / wdiff;
%%% end
%%% end % for i (blue)
%%% if isempty(varb)
%%% varb = -1;
%%% end
%%%
%%%% Find the partition point with the minimum variance.
%%%
%%% [minvarr minindr] = max(varr);
%%% [minvarg minindg] = max(varg);
%%% [minvarb minindb] = max(varb);
%%% [minvar mindim] = max([minvarr minvarg minvarb]);
%%%
%%% boxr = size( boxll, 1 );
%%% if mindim == 1 % Cut in red dimension.
%%% minindr = minindr + boxll(box,1);
%%% if box == boxr
%%% boxll = [boxll(1:box,:); minindr boxll(box,2) boxll(box,3)];
%%% else
%%% boxll = [boxll(1:box,:); minindr boxll(box,2) boxll(box,3); ...
%%% boxll(box+1:boxr,:)];
%%% E(box+2:boxr+1) = E(box+1:boxr); % Make space in E.
%%% end % if box == boxr
%%% boxur = [boxur(1:box-1,:); minindr boxur(box,2) boxur(box,3); ...
%%% boxur(box:boxr,:)];
%%% elseif mindim == 2 % Cut in green dimension.
%%% minindg = minindg + boxll(box,2);
%%% if box == boxr
%%% boxll = [boxll(1:box,:); boxll(box,1) minindg boxll(box,3)];
%%% else
%%% boxll = [boxll(1:box,:); boxll(box,1) minindg boxll(box,3); ...
%%% boxll(box+1:boxr,:)];
%%% E(box+2:boxr+1) = E(box+1:boxr); % Make space in E.
%%% end % if box == boxr
%%% boxur = [boxur(1:box-1,:); boxur(box,1) minindg boxur(box,3); ...
%%% boxur(box:boxr,:)];
%%% else % Cut in blue dimension.
%%% minindb = minindb + boxll(box,3);
%%% if box == boxr
%%% boxll = [boxll(1:box,:); boxll(box,1) boxll(box,2) minindb];
%%% else
%%% boxll = [boxll(1:box,:); boxll(box,1) boxll(box,2) minindb; ...
%%% boxll(box+1:boxr,:)];
%%% E(box+2:boxr+1) = E(box+1:boxr); % Make space in E.
%%% end % if box == boxr
%%% boxur = [boxur(1:box-1,:); boxur(box,1) boxur(box,2) minindb; ...
%%% boxur(box:boxr,:)];
%%% end % if mindim
%%%
%%%% Compute variance of two new boxes.
%%%
%%% boxr = box;
%%% for box=boxr:boxr+1
%%% if sum(boxur(box,:)-boxll(box,:)) > 3 % Box can be subdivided.
%%% E(box) = sum( M2( elem3d( rgbsize, ...
%%% [boxll(box,1) boxll(box,1) boxur(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2) boxll(box,2) boxur(box,2)], ...
%%% [boxur(box,3) boxll(box,3) boxll(box,3) boxur(box,3)] ) ) - ...
%%% M2( elem3d( rgbsize, ...
%%% [boxll(box,1) boxll(box,1) boxur(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2) boxll(box,2) boxur(box,2)], ...
%%% [boxll(box,3) boxur(box,3) boxur(box,3) boxll(box,3)] ) ) );
%%% wbox = sum( M0( elem3d( rgbsize, ...
%%% [boxll(box,1) boxll(box,1) boxur(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2) boxll(box,2) boxur(box,2)], ...
%%% [boxur(box,3) boxll(box,3) boxll(box,3) boxur(box,3)] ) ) - ...
%%% M0( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxll(box,2) boxur(box,2) boxur(box,2)], ...
%%% [boxll(box,3) boxur(box,3) boxur(box,3) boxll(box,3)] ) ) );
%%% if wbox
%%% M1box = [sum( M1r( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2) boxll(box,2) boxur(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) - ...
%%% M1r( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2) boxur(box,2) boxll(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) ) ...
%%% sum( M1g( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2) boxll(box,2) boxur(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) - ...
%%% M1g( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2) boxur(box,2) boxll(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) ) ...
%%% sum( M1b( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2) boxll(box,2) boxur(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) - ...
%%% M1b( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2) boxur(box,2) boxll(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) )];
%%% E(box) = E(box) - (M1box * M1box') / wbox;
%%% else
%%% disp(['Warning(2): Box with no population was created.']);
%%% E(box) = 0;
%%% end
%%% else % Box cannot be subdivided.
%%% E(box) = 0;
%%% end
%%% end % for box
%%% waitbar( .1 + .6 * color / (k-1) );
%%%end % for color
%%%
%%%% Place each point in image into proper box.
%%%
%%%% Build map of color values on top of M2.
%%%% and
%%%% Build matrix mapping rgb combo into boxes.
%%%
%%%boxr = size( boxll, 1 );
%%%map = zeros( boxr, 3 );
%%%for box=1:boxr
%%% if ~realmap
%%% map(box,:) = [sum( M1r( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2) boxll(box,2) boxur(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) - ...
%%% M1r( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2) boxur(box,2) boxll(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) ) ...
%%% sum( M1g( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2) boxll(box,2) boxur(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) - ...
%%% M1g( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2) boxur(box,2) boxll(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) ) ...
%%% sum( M1b( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxur(box,2) boxll(box,2) boxll(box,2) boxur(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) - ...
%%% M1b( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2) boxur(box,2) boxll(box,2)], ...
%%% [boxll(box,3) boxll(box,3) boxur(box,3) boxur(box,3)] ) ) )] / ...
%%% sum( M0( elem3d( rgbsize, ...
%%% [boxll(box,1) boxll(box,1) boxur(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxur(box,2) boxll(box,2) boxur(box,2)], ...
%%% [boxur(box,3) boxll(box,3) boxll(box,3) boxur(box,3)] ) ) - ...
%%% M0( elem3d( rgbsize, ...
%%% [boxll(box,1) boxur(box,1) boxll(box,1) boxur(box,1)], ...
%%% [boxll(box,2) boxll(box,2) boxur(box,2) boxur(box,2)], ...
%%% [boxll(box,3) boxur(box,3) boxur(box,3) boxll(box,3)] ) ) );
%%% end
%%% indices = ndx3d( rgbsize, boxll(box,1)+1:boxur(box,1), ...
%%% boxll(box,2)+1:boxur(box,2), boxll(box,3)+1:boxur(box,3) );
%%% M2( indices ) = box .* ones( size(indices) );
%%%% for gi=boxll(box,2)+1:boxur(box,2)
%%%% for bi=boxll(box,3)+1:boxur(box,3)
%%%% [row col] = elem3d(rgbsize,boxll(box,1)+1:boxur(box,1),gi,bi);
%%%% M2(row,col) = box .* ones(size(row))';
%%%% end
%%%% end
%%% waitbar( .7 + .35 * box / boxr );
%%%end
%%%
%%%% Map each rgb triple into image.
%%%
%%%if ~dith | realmap
%%% im = M2( elem3d( rgbsize, rq, gq, bq ) );
%%%end
%%%
%%%% Rescale color map to 0-1 or calculate means of boxes for real colormap.
%%%
%%%waitbar( 1 );
%%%
%%%if ~realmap
%%% mapscale = rgbsize - 2; % Map 0 onto 1 for 1d or 2d color space.
%%% mapscale = mapscale + (mapscale == 0);
%%% map = (map - 2) ./ mapscale(ones(boxr,1),:); % Map 2:Qx+1 to 0:1
%%%else
%%% for box=1:boxr
%%% indices = find( im == box );
%%% map(box,1) = sum( r( indices ) ) / length( indices );
%%% map(box,2) = sum( g( indices ) ) / length( indices );
%%% map(box,3) = sum( b( indices ) ) / length( indices );
%%% end % for box
%%%end
%%%
%%%if dith
%%% im = dither( r, g, b, map, max(Q), Qe );
%%%end
%%%
%%%close( bar );
%%%function r = cumsum3d( size, matrix )
%%%%CUMSUM3D Cumulative sum of 3D matrix packed in a 2D matrix.
%%%% B = CUMSUM3D( [M N P], A ) returns a M-by-N-by-P matrix B
%%%% containing the cumulative sum of A, also a M-by-N-by-P matrix.
%%%% Both B and A are stored in (M*N)-by-P matrices (see NDX3D).
%%%% The cumulative sum is computed along all 3 axes.
%%%%
%%%
%%%% Joseph M. Winograd 6-93
%%%% $Revision: 5.6 $ $Date: 1997/11/24 15:56:50 $
%%%
%%%M = size(1);
%%%N = size(2);
%%%P = size(3);
%%%
%%%r = cumsum( reshape( cumsum( reshape( ...
%%% cumsum( reshape( full(matrix), M, N*P ) )', ...
%%% N, M*P ) )', P, M*N ) )';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -