X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fimage-1.0.15%2Fblkproc.m;fp=octave_packages%2Fimage-1.0.15%2Fblkproc.m;h=48d741e5ee788f523b0cafd10118f0bb678eb995;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/image-1.0.15/blkproc.m b/octave_packages/image-1.0.15/blkproc.m new file mode 100644 index 0000000..48d741e --- /dev/null +++ b/octave_packages/image-1.0.15/blkproc.m @@ -0,0 +1,204 @@ +## 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{B} = } blkproc (@var{A}, [@var{m},@var{n}], @var{fun}) +## @deftypefnx {Function File} {@var{B} = } blkproc (@var{A}, [@var{m},@var{n}], @var{fun}, ...) +## @deftypefnx {Function File} {@var{B} = } blkproc (@var{A}, [@var{m},@var{n}], [@var{mborder},@var{nborder}], @var{fun}, @var{...}) +## @deftypefnx {Function File} {@var{B} = } blkproc (@var{A}, 'indexed', ...) +## Processes image in blocks using user-supplied function. +## +## @code{B=blkproc(A,[m,n],fun)} divides image @var{A} in +## @var{m}-by-@var{n} blocks, and passes them to user-supplied function +## @var{fun}, which result is concatenated to build returning matrix +## @var{B}. If padding is needed to build @var{m}-by-@var{n}, it is added +## at the bottom and right borders of the image. 0 is used as a padding +## value. +## +## @code{B=blkproc(A,[m,n],fun,...)} behaves as described above but +## passes extra parameters to function @var{fun}. +## +## @code{B=blkproc(A,[m,n],[mborder,nborder],fun,...)} behaves as +## described but uses blocks which overlap with neighbour blocks. +## Overlapping dimensions are @var{mborder} vertically and @var{nborder} +## horizontally. This doesn't change the number of blocks in an image +## (which depends only on size(@var{A}) and [@var{m},@var{n}]). Adding a +## border requires extra padding on all edges of the image. 0 is used as +## a padding value. +## +## @code{B=blkproc(A,'indexed',...)} assumes that @var{A} is an indexed +## image, so it pads the image using proper value: 0 for uint8 and +## uint16 images and 1 for double images. Keep in mind that if 'indexed' +## is not specified padding is always done using 0. +## +## @seealso{colfilt,inline,bestblk} +## @end deftypefn + +## Author: Josep Mones i Teixidor + +function B = blkproc(A, varargin) + if(nargin<3) + error("blkproc: invalid number of parameters."); + endif + + ## check 'indexed' presence + indexed=false; + p=1; + if(ischar(varargin{1}) && strcmp(varargin{1}, "indexed")) + indexed=true; + p+=1; + if(isa(A,"uint8") || isa(A,"uint16")) + padval=0; + else + padval=1; + endif + else + padval=0; + endif + + ## check [m,n] + if(!isvector(varargin{p})) + error("blkproc: expected [m,n] but param is not a vector."); + endif + if(length(varargin{p})!=2) + error("blkproc: expected [m,n] but param has wrong length."); + endif + sblk=varargin{p}(:); + p+=1; + + ## check [mborder,nborder] + if(nargin ischar +% +% Revision 1.4 2004/11/15 16:04:20 pkienzle +% Fix tests for functions which return boolean matrices +% +% Revision 1.3 2004/09/03 17:49:37 jmones +% Improved uint8 and uint16 padding expections +% +% Revision 1.2 2004/09/03 13:40:13 jmones +% Check result has same class as function result, and improved fun param checking +% +% Revision 1.1 2004/08/15 19:27:46 jmones +% blkproc: block process an image using user-supplied function +% +%