1 ## Copyright (C) 2004 Josep Mones i Teixidor
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{siz} = } bestblk ([@var{m} @var{n}], @var{k})
18 ## @deftypefnx {Function File} {[@var{mb} @var{nb}] = } bestblk ([@var{m} @var{n}], @var{k})
19 ## Calculates the best size of block for block processing.
21 ## @code{siz=bestblk([m,n],k)} calculates the optimal block size for block
22 ## processing for a @var{m}-by-@var{n} image. @var{k} is the maximum
23 ## side dimension of the block. Its default value is 100. @var{siz} is a
24 ## row vector which contains row and column dimensions for the block.
26 ## @code{[mb,nb]=bestblk([m,n],k)} behaves as described above but
27 ## returns block dimensions to @var{mb} and @var{nb}.
29 ## @strong{Algorithm:}
31 ## For each dimension (@var{m} and @var{n}), it follows this algorithm:
33 ## 1.- If dimension is less or equal than @var{k}, it returns the
36 ## 2.- If not then returns the value between
37 ## @code{round(min(dimension/10,k/2))} which minimizes padding.
44 ## Author: Josep Mones i Teixidor <jmones@puntbarra.com>
46 function [varargout] = bestblk(ims,k)
47 if(nargin<1 || nargin>2)
48 usage("siz=bestblk([m,n],k), [mb,nb]=bestblk([m,n],k)");
51 usage("siz=bestblk([m,n],k), [mb,nb]=bestblk([m,n],k)");
57 error("bestblk: first parameter is not a vector.");
61 error("bestblk: length of first parameter is not 2.");
67 for i=round(min(mi/10,k/2)):k
79 for i=round(min(ni/10,k/2)):k
98 %! siz = bestblk ([200; 10], 50);
101 %!assert(bestblk([300;100],150),[30;100]);
102 %!assert(bestblk([256,128],17),[16;16]);
105 % Revision 1.3 2007/03/23 16:14:36 adb014
106 % Update the FSF address
108 % Revision 1.2 2007/01/04 23:44:22 hauberg
109 % Minor changes in help text
111 % Revision 1.1 2006/08/20 12:59:31 hauberg
112 % Changed the structure to match the package system
114 % Revision 1.2 2005/07/03 01:10:19 pkienzle
115 % Try to correct for missing newline at the end of the file
117 % Revision 1.1 2004/08/15 19:01:05 jmones
118 % bestblk added: Calculates best block size for block processing