X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fimage-1.0.15%2Fbestblk.m;fp=octave_packages%2Fimage-1.0.15%2Fbestblk.m;h=abe29f8ec27752c54e942d471cbb69c3fa10c949;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/image-1.0.15/bestblk.m b/octave_packages/image-1.0.15/bestblk.m new file mode 100644 index 0000000..abe29f8 --- /dev/null +++ b/octave_packages/image-1.0.15/bestblk.m @@ -0,0 +1,118 @@ +## Copyright (C) 2004 Josep Mones i Teixidor +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; If not, see . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{siz} = } bestblk ([@var{m} @var{n}], @var{k}) +## @deftypefnx {Function File} {[@var{mb} @var{nb}] = } bestblk ([@var{m} @var{n}], @var{k}) +## Calculates the best size of block for block processing. +## +## @code{siz=bestblk([m,n],k)} calculates the optimal block size for block +## processing for a @var{m}-by-@var{n} image. @var{k} is the maximum +## side dimension of the block. Its default value is 100. @var{siz} is a +## row vector which contains row and column dimensions for the block. +## +## @code{[mb,nb]=bestblk([m,n],k)} behaves as described above but +## returns block dimensions to @var{mb} and @var{nb}. +## +## @strong{Algorithm:} +## +## For each dimension (@var{m} and @var{n}), it follows this algorithm: +## +## 1.- If dimension is less or equal than @var{k}, it returns the +## dimension value. +## +## 2.- If not then returns the value between +## @code{round(min(dimension/10,k/2))} which minimizes padding. +## +## +## @seealso{blkproc} +## @end deftypefn + + +## Author: Josep Mones i Teixidor + +function [varargout] = bestblk(ims,k) + if(nargin<1 || nargin>2) + usage("siz=bestblk([m,n],k), [mb,nb]=bestblk([m,n],k)"); + endif + if(nargout>2) + usage("siz=bestblk([m,n],k), [mb,nb]=bestblk([m,n],k)"); + endif + if(nargin<2) + k=100; + endif + if(!isvector(ims)) + error("bestblk: first parameter is not a vector."); + endif + ims=ims(:); + if(length(ims)!=2) + error("bestblk: length of first parameter is not 2."); + endif + + mb=mi=ims(1); + p=mi; + if(mi>k) + for i=round(min(mi/10,k/2)):k + pt=rem(mi,i); + if(ptk) + for i=round(min(ni/10,k/2)):k + pt=rem(ni,i); + if(pt