Mercurial > hg > octave-image
changeset 560:1d04ebf01532
image: replace calls to usage() by print_usage() (usage is redundant and going to be deprecated in 3.8). Also small improvements on texinfo and use of defaulr arguments for simpler input check.
author | carandraug |
---|---|
date | Mon, 16 Apr 2012 11:47:35 +0000 |
parents | 926ecec891e4 |
children | c45838839d86 |
files | DESCRIPTION inst/applylut.m inst/bestblk.m inst/bwmorph.m inst/cmpermute.m inst/cmunique.m inst/col2im.m inst/colorgradient.m inst/dilate.m inst/erode.m inst/fftconv2.m inst/im2bw.m inst/im2col.m inst/imadjust.m inst/imdither.m inst/imnoise.m inst/makelut.m inst/qtdecomp.m inst/qtgetblk.m inst/qtsetblk.m inst/roicolor.m inst/uintlut.m |
diffstat | 22 files changed, 474 insertions(+), 888 deletions(-) [+] |
line wrap: on
line diff
--- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,5 +11,5 @@ operations, linear filtering, and much more. Depends: octave (>= 3.4.0), signal Autoload: yes -License: GPL version 2 or later +License: GPLv3+, simplified BSD Url: http://octave.sf.net
--- a/inst/applylut.m +++ b/inst/applylut.m @@ -1,20 +1,20 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{A} = } applylut (@var{BW},@var{LUT}) +## @deftypefn {Function File} {@var{A} =} applylut (@var{BW}, @var{LUT}) ## Uses lookup tables to perform a neighbour operation on binary images. ## ## A = applylut(BW,LUT) returns the result of a neighbour operation @@ -28,11 +28,9 @@ ## @seealso{makelut} ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function A = applylut(BW, LUT) +function A = applylut (BW, LUT) if (nargin != 2) - usage ("A = applylut(BW, LUT)"); + print_usage; endif nq=log2(length(LUT)); @@ -48,15 +46,9 @@ %! lut = makelut (inline ('sum (x (:)) >= 3', 'x'), 3); %! S = applylut (eye (5), lut); %! disp (S) -%! ## Everything should be 0 despite a diagonal which -%! ## doesn't reach borders. - +%! ## Everything should be 0 despite a diagonal which doesn't reach borders. %!assert(prod(applylut(eye(3),makelut(inline('x(1,1)==1','x'),2))==eye(3))==1); % 2-by-2 test %!assert(prod(applylut(eye(3),makelut(inline('x(2,2)==1','x'),3))==eye(3))==1); % 3-by-3 test %!assert(prod(applylut(eye(3),makelut(inline('x(3,3)==1','x'),3))== \ -%! applylut(eye(3),makelut(inline('x(2,2)==1','x'),2)))==1); - - - - +%! applylut(eye(3),makelut(inline('x(2,2)==1','x'),2)))==1);
--- a/inst/bestblk.m +++ b/inst/bestblk.m @@ -1,17 +1,17 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn {Function File} {@var{siz} = } bestblk ([@var{m} @var{n}], @var{k}) @@ -40,20 +40,10 @@ ## @seealso{blkproc} ## @end deftypefn - -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -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)) +function [varargout] = bestblk (ims, k = 100) + if (nargin < 1 || nargin > 2 || nargout > 2) + print_usage; + elseif (!isvector (ims)) error("bestblk: first parameter is not a vector."); endif ims=ims(:); @@ -67,8 +57,8 @@ for i=round(min(mi/10,k/2)):k pt=rem(mi,i); if(pt<p) - p=pt; - mb=i; + p=pt; + mb=i; endif endfor endif @@ -79,8 +69,8 @@ for i=round(min(ni/10,k/2)):k pt=rem(ni,i); if(pt<p) - p=pt; - nb=i; + p=pt; + nb=i; endif endfor endif @@ -100,19 +90,3 @@ %!assert(bestblk([300;100],150),[30;100]); %!assert(bestblk([256,128],17),[16;16]); - -% $Log$ -% Revision 1.3 2007/03/23 16:14:36 adb014 -% Update the FSF address -% -% Revision 1.2 2007/01/04 23:44:22 hauberg -% Minor changes in help text -% -% Revision 1.1 2006/08/20 12:59:31 hauberg -% Changed the structure to match the package system -% -% Revision 1.2 2005/07/03 01:10:19 pkienzle -% Try to correct for missing newline at the end of the file -% -% Revision 1.1 2004/08/15 19:01:05 jmones -% bestblk added: Calculates best block size for block processing
--- a/inst/bwmorph.m +++ b/inst/bwmorph.m @@ -1,21 +1,21 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{BW2} = } bwmorph (@var{BW},@var{operation}) -## @deftypefnx {Function File} {@var{BW2} = } bwmorph (@var{BW},@var{operation},@var{n}) +## @deftypefn {Function File} {@var{BW2} =} bwmorph (@var{BW}, @var{operation}) +## @deftypefnx {Function File} {@var{BW2} =} bwmorph (@var{BW}, @var{operation}, @var{n}) ## Perform a morphological operation on a binary image. ## ## BW2=bwmorph(BW,operation) performs a morphological operation @@ -187,23 +187,16 @@ ## @seealso{imdilate, imerode, imtophat, imbothat, makelut, applylut} ## @end deftypefn - ## TODO: As soon as Octave doesn't segfault when assigning values to a ## TODO: bool matrix, remove all conversions from lut to logical and ## TODO: just create it as a logical from the beginning. ## TODO: n behaviour should be tested in all cases for compatibility. -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function BW2 = bwmorph(BW, operation, n) +function BW2 = bwmorph (BW, operation, n = 1) if(nargin<2 || nargin>3) - usage("BW2=bwmorph(BW, operation [,n])"); - endif - if(nargin<3) - n=1; - endif - if(n<0) + print_usage; + elseif(n<0) error("bwmorph: n should be > 0"); elseif(n==0) ## we'll just return the same matrix (check this!) BW2=BW; @@ -587,38 +580,3 @@ %!assert(bwmorph(slBW,'skel-lantuejoul',2),[rslBW(1:8,:);logical(zeros(4,7))]); %!assert(bwmorph(slBW,'skel-lantuejoul',3),rslBW); %!assert(bwmorph(slBW,'skel-lantuejoul',Inf),rslBW); - - -% -% $Log$ -% Revision 1.4 2007/03/23 16:14:36 adb014 -% Update the FSF address -% -% Revision 1.3 2007/01/04 23:41:47 hauberg -% Minor changes in help text -% -% Revision 1.2 2006/10/15 08:04:55 hauberg -% Fixed texinfo in bwmorph -% -% Revision 1.1 2006/08/20 12:59:32 hauberg -% Changed the structure to match the package system -% -% Revision 1.6 2004/09/16 02:14:40 pkienzle -% Use frivolous uint8() call to block tests for version 2.1.57 and earlier -% -% Revision 1.5 2004/09/15 20:36:57 jmones -% logical(1) => true -% -% Revision 1.4 2004/09/15 20:00:00 jmones -% Updated tests to match Gonzalez&Woods example -% -% Revision 1.3 2004/09/15 13:51:10 pkienzle -% Use logical in tests; reduce number of shared variables in tests. -% -% Revision 1.2 2004/09/01 22:35:47 jmones -% Added Lantuejoul skeletonizing algorithm from Gonzalez&Woods -% -% Revision 1.1 2004/08/15 19:47:04 jmones -% bwmorph added: Perform a morphological operation on a binary image -% -%
--- a/inst/cmpermute.m +++ b/inst/cmpermute.m @@ -1,21 +1,21 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{Y}, @var{newmap}] = } cmpermute (@var{X},@var{map}) -## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] = } cmpermute (@var{X},@var{map},@var{index}) +## @deftypefn {Function File} {[@var{Y}, @var{newmap}] =} cmpermute (@var{X}, @var{map}) +## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} cmpermute (@var{X}, @var{map}, @var{index}) ## Reorders colors in a colormap. ## ## @code{[Y,newmap]=cmpermute(X,map)} rearranges colormap @var{map} @@ -33,19 +33,16 @@ ## ## @end deftypefn - -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function [Y, newmap] = cmpermute(X, map, index) +function [Y, newmap] = cmpermute (X, map, index) switch(nargin) case(2) index=randperm(rows(map)); case(3) if(!isvector(index) || length(index)!=rows(map)) - error("cmpermute: invalid parameter index."); + error("cmpermute: invalid parameter index."); endif otherwise - usage("[Y, newmap] = cmpermute(X, map [, index])"); + print_usage; endswitch ## new colormap @@ -54,7 +51,7 @@ ## build reverse index rindex = zeros(size(index)); rindex(index) = 1:length(index); - + ## readapt indices if(isa(X,"uint8")) rindex=uint8(rindex-1); @@ -65,7 +62,6 @@ endif endfunction - %!demo %! [Y,newmap]=cmpermute([1:4],hot(4),4:-1:1) %! # colormap will be arranged in reverse order (so will image) @@ -105,28 +101,3 @@ %! assert(newmap(rows(newmap):-1:1,:),map); %! # we expect reversed indices in image %! assert(X,max(Y(:))+1-Y); - -% -% $Log$ -% Revision 1.3 2007/03/23 16:14:36 adb014 -% Update the FSF address -% -% Revision 1.2 2007/01/04 23:44:22 hauberg -% Minor changes in help text -% -% Revision 1.1 2006/08/20 12:59:32 hauberg -% Changed the structure to match the package system -% -% Revision 1.4 2004/09/08 15:01:28 pkienzle -% Redo tests: reduce # of shared variables; force full range of uint8 -% -% Revision 1.3 2004/09/08 14:13:08 jmones -% Synchronized with cmunique. uint8 support added. Tests working for 2.1.58 -% -% Revision 1.2 2004/08/18 14:57:42 jmones -% speed improvement suggested by Paul Kienzle -% -% Revision 1.1 2004/08/17 19:18:42 jmones -% cmpermute added: Reorders colors in a colormap -% -%
--- a/inst/cmunique.m +++ b/inst/cmunique.m @@ -1,22 +1,22 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{Y}, @var{newmap}] = } cmunique (@var{X},@var{map}) -## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] = } cmunique (@var{RGB}) -## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] = } cmunique (@var{I}) +## @deftypefn {Function File} {[@var{Y}, @var{newmap}] =} cmunique (@var{X}, @var{map}) +## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} cmunique (@var{RGB}) +## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} cmunique (@var{I}) ## Finds colormap with unique colors and corresponding image. ## ## @code{[Y,newmap]=cmunique(X,map)} returns an indexed image @var{y} @@ -50,12 +50,9 @@ ## ## @end deftypefn - -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function [Y, newmap] = cmunique(P1, P2) +function [Y, newmap] = cmunique (P1, P2) if (nargin<1 || nargin>2) - usage("[Y, newmap] = cmunique(X, map), [Y, newmap] = cmunique(RGB), [Y, newmap] = cmunique(I)"); + print_usage; endif @@ -70,17 +67,17 @@ else switch(size(P1,3)) case(1) - ## I case - [newmap,i,j]=unique(P1); ## calculate unique colormap - newmap=repmat(newmap,1,3); ## get a RGB colormap - Y=reshape(j,rows(P1),columns(P1)); ## Y is j reshaped + ## I case + [newmap,i,j]=unique(P1); ## calculate unique colormap + newmap=repmat(newmap,1,3); ## get a RGB colormap + Y=reshape(j,rows(P1),columns(P1)); ## Y is j reshaped case(3) - ## RGB case - map=[P1(:,:,1)(:), P1(:,:,2)(:), P1(:,:,3)(:)]; ## build a map with all values - [newmap,i,j]=unique(map, 'rows'); ## calculate unique colormap - Y=reshape(j,rows(P1),columns(P1)); ## Y is j reshaped + ## RGB case + map=[P1(:,:,1)(:), P1(:,:,2)(:), P1(:,:,3)(:)]; ## build a map with all values + [newmap,i,j]=unique(map, 'rows'); ## calculate unique colormap + Y=reshape(j,rows(P1),columns(P1)); ## Y is j reshaped otherwise - error("cmunique: first parameter is invalid."); + error("cmunique: first parameter is invalid."); endswitch ## if image was uint8 or uint16 we have to convert newmap to [0,1] range @@ -93,17 +90,14 @@ ## convert Y to uint8 (0-based indices then) Y=uint8(Y-1); endif - endfunction - %!demo %! [Y,newmap]=cmunique([1:4;5:8],[hot(4);hot(4)]) %! # Both rows are equal since map maps colors to the same value %! # cmunique will give the same indices to both - %!# This triggers invalid first parameter %!error(cmunique(zeros(3,3,2))); @@ -182,30 +176,3 @@ %! assert(Id,newmap(:,1)(Y+1)); %! assert(Id,newmap(:,2)(Y+1)); %! assert(Id,newmap(:,3)(Y+1)); - -% -% $Log$ -% Revision 1.3 2007/03/23 16:14:36 adb014 -% Update the FSF address -% -% Revision 1.2 2007/01/04 23:44:22 hauberg -% Minor changes in help text -% -% Revision 1.1 2006/08/20 12:59:32 hauberg -% Changed the structure to match the package system -% -% Revision 1.4 2004/09/08 16:06:31 jmones -% Solved problem with uint8 indexing and reduced tests on types (suggested by P. Kienzle) -% -% Revision 1.3 2004/09/03 17:07:26 jmones -% Support for uint8 and uint16 types added. -% -% Revision 1.2 2004/08/17 15:48:03 jmones -% Clarified expected data for RGB images in doc -% -% Revision 1.1 2004/08/17 15:45:40 jmones -% cmunique: Finds colormap with unique colors and corresponding image -% -% - -
--- a/inst/col2im.m +++ b/inst/col2im.m @@ -1,21 +1,21 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{A} = } col2im (@var{B}, [@var{m},@var{n}], [@var{mm},@var{nn}], @var{block_type}) -## @deftypefnx {Function File} {@var{A} = } col2im (@var{B}, [@var{m},@var{n}], [@var{mm},@var{nn}]) +## @deftypefn {Function File} {@var{A} =} col2im (@var{B}, [@var{m},@var{n}], [@var{mm},@var{nn}], @var{block_type}) +## @deftypefnx {Function File} {@var{A} =} col2im (@var{B}, [@var{m},@var{n}], [@var{mm},@var{nn}]) ## Rearranges matrix columns into blocks. ## ## @code{A=col2im(B,[m,n],[mm,nn],block_type)} rearranges columns of @@ -42,15 +42,9 @@ ## @seealso{im2col} ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function A = col2im(B, sblock, sb, block_type) - if(nargin<3 || nargin>4) - usage("A=col2im(B, [m,n], [mm,nn] [, block_type])"); - endif - - if(nargin!=4) - block_type='sliding'; +function A = col2im (B, sblock, sb, block_type = "sliding") + if(nargin < 3 || nargin > 4) + print_usage; endif ## common checks @@ -72,39 +66,39 @@ switch(block_type) case('distinct') if(rows(B)!=m*n) - error("col2im: B height must be m*n for 'distinct' block_type."); + error("col2im: B height must be m*n for 'distinct' block_type."); endif if(rem(mm,m)!=0) - error("col2im: mm should be multiple of m"); + error("col2im: mm should be multiple of m"); endif if(rem(nn,n)!=0) - error("col2im: nn should be multiple of n"); + error("col2im: nn should be multiple of n"); endif mt=mm/m; nt=nn/n; if(columns(B)<mt*nt) - error("col2im: B's width is too small (should be mm*nn/(m*m))."); + error("col2im: B's width is too small (should be mm*nn/(m*m))."); endif c=1; for i=1:mt - ## TODO: check if we can horzcat([],uint8([10;11])) in a - ## future Octave version > 2.1.58 in order to deuglify this! - r=reshape(B(:,c),m,n); - c+=1; - for j=2:nt - r=horzcat(r, reshape(B(:,c),m,n)); - c+=1; - endfor - if(i==1) ## this workarrounds a bug in ver<=2.1.57 cat implementation - A=r; - else - A=vertcat(A,r); - endif + ## TODO: check if we can horzcat([],uint8([10;11])) in a + ## future Octave version > 2.1.58 in order to deuglify this! + r=reshape(B(:,c),m,n); + c+=1; + for j=2:nt + r=horzcat(r, reshape(B(:,c),m,n)); + c+=1; + endfor + if(i==1) ## this workarrounds a bug in ver<=2.1.57 cat implementation + A=r; + else + A=vertcat(A,r); + endif endfor - + case('sliding') if(!all(size(B)==[1,(mm-m+1)*(nn-n+1)])) - error("col2im: wrong B size. Should be 1-by-(mm-m+1)*(nn-n+1)."); + error("col2im: wrong B size. Should be 1-by-(mm-m+1)*(nn-n+1)."); endif A=reshape(B, mm-m+1, nn-n+1); @@ -120,7 +114,6 @@ %! C=col2im(B,[2,5],[4,10],'distinct') %! # Divide A using distinct blocks and reverse operation - %!shared B, Ad %! v=[1:10]'; %! r=reshape(v,2,5); @@ -149,32 +142,8 @@ %!assert(col2im(ones(1,(10-2+1)*(7-3+1)),[2,3],[10,7]), ones((10-2+1),(7-3+1))); %!assert(col2im(ones(1,(10-2+1)*(7-3+1)),[2,3],[10,7],'sliding'), ones((10-2+1),(7-3+1))); - %!# disctint on uint8 %!assert(col2im(uint8(B),[2,5],[6,10],'distinct'), uint8(Ad)); %!# now sliding on uint8 %!assert(col2im(ones(1,(10-2+1)*(7-3+1),"uint8"),[2,3],[10,7]), ones((10-2+1),(7-3+1),"uint8")); - - -% -% $Log$ -% Revision 1.4 2007/03/23 16:14:36 adb014 -% Update the FSF address -% -% Revision 1.3 2007/01/04 23:46:17 hauberg -% Minor changes in help text -% -% Revision 1.2 2007/01/04 23:37:54 hauberg -% Minor changes in help text -% -% Revision 1.1 2006/08/20 12:59:32 hauberg -% Changed the structure to match the package system -% -% Revision 1.2 2004/09/03 17:57:42 jmones -% Added support for int* and uint* types -% -% Revision 1.1 2004/08/18 14:39:07 jmones -% im2col and col2im added -% -%
--- a/inst/colorgradient.m +++ b/inst/colorgradient.m @@ -1,5 +1,8 @@ +## Author: Paul Kienzle <pkienzle@users.sf.net> +## This program is granted to the public domain. + ## -*- texinfo -*- -## @deftypefn {Function File} @var{M} = colorgradient(@var{C}, @var{w}, @var{n}) +## @deftypefn {Function File} {@var{M} =} colorgradient (@var{C}, @var{w}, @var{n}) ## Define a colour map which smoothly traverses the given colors. ## @var{C} contains the colours, one row per r,g,b value. ## @var{w}(i) is the relative length of the transition from colour i to colour i+1 @@ -14,12 +17,9 @@ ## @end example ## @end deftypefn -## This program is granted to the public domain. -## Author: Paul Kienzle <pkienzle@users.sf.net> - -function ret = colorgradient(C,w,n) +function ret = colorgradient (C, w, n) if nargin < 1 || nargin > 3 - usage("M = colorgradient(C,w,n)") + print_usage; endif if nargin == 1
--- a/inst/dilate.m +++ b/inst/dilate.m @@ -1,22 +1,22 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{BW2} = } dilate (@var{BW1},@var{SE}) -## @deftypefnx {Function File} {@var{BW2} = } dilate (@var{BW1},@var{SE},@var{alg}) -## @deftypefnx {Function File} {@var{BW2} = } dilate (@var{BW1},@var{SE},...,@var{n}) +## @deftypefn {Function File} {@var{BW2} =} dilate (@var{BW1}, @var{SE}) +## @deftypefnx {Function File} {@var{BW2} =} dilate (@var{BW1}, @var{SE}, @var{alg}) +## @deftypefnx {Function File} {@var{BW2} =} dilate (@var{BW1}, @var{SE}, @dots{}, @var{n}) ## Perform a dilation morphological operation on a binary image. ## ## @emph{warning}: @code{dilate} has been deprecated in favor of @@ -37,21 +37,24 @@ ## BW2 = dilate(BW1, SE, alg) returns the result of a dilation operation ## using algorithm @var{alg}. Only 'spatial' is implemented at the moment. ## -## BW2 = dilate(BW1, SE, ..., n) returns the result of @var{n} dilation +## BW2 = dilate(BW1, SE, @dots{}, n) returns the result of @var{n} dilation ## operations on @var{BW1}. ## ## @seealso{erode} ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function BW2 = dilate(BW1, SE, a, b) - warning ("'dilate' has been deprecated in favor of 'imdilate'. This function will be removed from future versions of the 'image' package"); +function BW2 = dilate (BW1, SE, a, b) + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "`dilate' has been deprecated in favor of `imdilate'. This function will be removed from future versions of the `image' package"); + endif alg='spatial'; n=1; if (nargin < 1 || nargin > 4) - usage ("BW2 = dilate(BW1, SE [, alg] [, n])"); + print_usage; endif if nargin == 4 alg=a;
--- a/inst/erode.m +++ b/inst/erode.m @@ -1,22 +1,22 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{BW2} = } erode (@var{BW1},@var{SE}) -## @deftypefnx {Function File} {@var{BW2} = } erode (@var{BW1},@var{SE},@var{alg}) -## @deftypefnx {Function File} {@var{BW2} = } erode (@var{BW1},@var{SE},...,@var{n}) +## @deftypefn {Function File} {@var{BW2} =} erode (@var{BW1}, @var{SE}) +## @deftypefnx {Function File} {@var{BW2} =} erode (@var{BW1}, @var{SE}, @var{alg}) +## @deftypefnx {Function File} {@var{BW2} =} erode (@var{BW1}, @var{SE}, @dots{}, @var{n}) ## Perform an erosion morphological operation on a binary image. ## ## @emph{warning}: @code{erode} has been deprecated in favor of @@ -37,21 +37,24 @@ ## BW2 = erode(BW1, SE, alg) returns the result of a erosion operation ## using algorithm @var{alg}. Only 'spatial' is implemented at the moment. ## -## BW2 = erosion(BW1, SE, ..., n) returns the result of @var{n} erosion +## BW2 = erosion(BW1, SE, @dots{}, n) returns the result of @var{n} erosion ## operations on @var{BW1}. ## ## @seealso{dilate} ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function BW2 = erode(BW1, SE, a, b) - warning ("'erode' has been deprecated in favor of 'imerode'. This function will be removed from future versions of the 'image' package"); +function BW2 = erode (BW1, SE, a, b) + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "`erode' has been deprecated in favor of `imerode'. This function will be removed from future versions of the `image' package"); + endif alg='spatial'; n=1; if (nargin < 1 || nargin > 4) - usage ("BW2 = erode(BW1, SE [, alg] [, n])"); + print_usage; endif if nargin == 4 alg=a; @@ -86,9 +89,5 @@ %! erode(ones(5,5),ones(3,3)) %! % creates a zeros border around ones. - - %!assert(erode([0,1,0;1,1,1;0,1,0],[0,0,0;0,0,1;0,1,1])==[1,0,0;0,0,0;0,0,0]); %!assert(erode([0,1,0;1,1,1;0,1,0],[0,1;1,1])==[1,0,0;0,0,0;0,0,0]); - -
--- a/inst/fftconv2.m +++ b/inst/fftconv2.m @@ -1,26 +1,25 @@ ## Copyright (C) 2004 Stefan van der Walt <stefan@sun.ac.za> -## -## This program is free software; redistribution and use in source and -## binary forms, with or without modification, are permitted provided that -## the following conditions are met: +## All rights reserved. ## -## 1. Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## 2. Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in the -## documentation and/or other materials provided with the distribution. +## Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are met: ## -## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +## 1 Redistributions of source code must retain the above copyright notice, +## this list of conditions and the following disclaimer. +## 2 Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in the +## documentation and/or other materials provided with the distribution. +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' +## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -## SUCH DAMAGE. +## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR +## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## -*- texinfo -*- ## @deftypefn {Function File} fftconv2 (@var{a}, @var{b}, @var{shape})
--- a/inst/im2bw.m +++ b/inst/im2bw.m @@ -1,31 +1,28 @@ -## Copyright (C) 2000 Kai Habel +## Copyright (C) 2000 Kai Habel <kai.habel@gmx.de> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} @var{BW}= im2bw (@var{I},threshold) -## @deftypefnx {Function File} @var{BW}= im2bw (@var{X},@var{cmap},threshold) +## @deftypefn {Function File} {@var{BW} =} im2bw (@var{I}, threshold) +## @deftypefnx {Function File} {@var{BW} =} im2bw (@var{X}, @var{cmap}, threshold) ## Converts image data types to a black-white (binary) image. ## The treshold value should be in the range [0,1]. ## @end deftypefn -## Author: Kai Habel <kai.habel@gmx.de> -## Date: 19. March 2000 - function BW = im2bw (img, a, b) if (nargin < 2 || nargin > 3) - usage("im2bw: number of arguments must be 2 or 3"); + print_usage; endif ## Convert img to gray scale
--- a/inst/im2col.m +++ b/inst/im2col.m @@ -1,22 +1,22 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{B} = } im2col (@var{A}, [@var{m},@var{n}], @var{block_type}) -## @deftypefnx {Function File} {@var{B} = } im2col (@var{A}, [@var{m},@var{n}]) -## @deftypefnx {Function File} {@var{B} = } im2col (@var{A}, 'indexed', ...) +## @deftypefn {Function File} {@var{B} =} im2col (@var{A}, [@var{m}, @var{n}], @var{block_type}) +## @deftypefnx {Function File} {@var{B} =} im2col (@var{A}, [@var{m}, @var{n}]) +## @deftypefnx {Function File} {@var{B} =} im2col (@var{A}, 'indexed', @dots{}) ## Rearranges image blocks into columns. ## ## @code{B=im2col(A, [m, n], blocktype)} rearranges blocks in @var{A} @@ -47,7 +47,7 @@ ## @code{B=im2col(A,[m,n])} takes @code{distinct} as a default value for ## @var{block_type}. ## -## @code{B=im2col(A,'indexed',...)} will treat @var{A} as an indexed +## @code{B=im2col(A,'indexed', @dots{})} will treat @var{A} as an indexed ## image, so it will pad using 1 if @var{A} is double. All other cases ## (incluing indexed matrices with uint8 and uint16 types and ## non-indexed images) will use 0 as padding value. @@ -58,11 +58,9 @@ ## @seealso{col2im} ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function B = im2col(A, varargin) - if(nargin<2 || nargin>4) - usage("B=im2col(B [, 'indexed'], [m,n] [, block_type])"); +function B = im2col (A, varargin) + if(nargin < 2 || nargin > 4) + print_usage; endif ## check 'indexed' presence @@ -70,14 +68,14 @@ p=1; if(ischar(varargin{1}) && strcmp(varargin{1}, "indexed")) if(nargin<3) - usage("B=im2col(B [, 'indexed'], [m,n] [, block_type])"); + print_usage; endif indexed=true; p+=1; if(isa(A,"uint8") || isa(A,"uint16")) - padval=0; + padval=0; else - padval=1; + padval=1; endif else padval=0; @@ -106,9 +104,8 @@ ## if we didn't have 'indexed' but had 4 parameters there's an error if(nargin>p) - usage("B=im2col(B [, 'indexed'], [m,n] [, block_type])"); + print_usage; endif - ## common checks if(!ismatrix(A)) @@ -121,42 +118,42 @@ sp=mod(-size(A)',[m;n]); if(any(sp)) - A=padarray(A,sp,padval,'post'); + A=padarray(A,sp,padval,'post'); endif ## iterate through all blocks B=[]; for i=1:m:size(A,1) ## up to bottom - for j=1:n:size(A,2) ## left to right - ## TODO: check if we can horzcat([],uint8([10;11])) in a - ## future Octave version > 2.1.58 - if(isempty(B)) - B=A(i:i+m-1,j:j+n-1)(:); - else - B=horzcat(B, A(i:i+m-1,j:j+n-1)(:)); - endif - endfor + for j=1:n:size(A,2) ## left to right + ## TODO: check if we can horzcat([],uint8([10;11])) in a + ## future Octave version > 2.1.58 + if(isempty(B)) + B=A(i:i+m-1,j:j+n-1)(:); + else + B=horzcat(B, A(i:i+m-1,j:j+n-1)(:)); + endif + endfor endfor case('sliding') if(indexed) - disp("WARNING: 'indexed' has no sense when using sliding."); + disp("WARNING: 'indexed' has no sense when using sliding."); endif if(m>size(A,1) || n>size(A,2)) - error("im2col: block size can't be greater than image size in sliding"); + error("im2col: block size can't be greater than image size in sliding"); endif ## TODO: check if matlab uses top-down and left-right order B=[]; for j=1:1:size(A,2)-n+1 ## left to right - for i=1:1:size(A,1)-m+1 ## up to bottom - ## TODO: check if we can horzcat([],uint8([10;11])) in a - ## future Octave version > 2.1.58 - if(isempty(B)) - B=A(i:i+m-1,j:j+n-1)(:); - else - B=horzcat(B, A(i:i+m-1,j:j+n-1)(:)); - endif - endfor + for i=1:1:size(A,1)-m+1 ## up to bottom + ## TODO: check if we can horzcat([],uint8([10;11])) in a + ## future Octave version > 2.1.58 + if(isempty(B)) + B=A(i:i+m-1,j:j+n-1)(:); + else + B=horzcat(B, A(i:i+m-1,j:j+n-1)(:)); + endif + endfor endfor otherwise @@ -215,31 +212,3 @@ %!# now sliding uint8 & uint16 %!assert(im2col(uint8(As),[2,4],'sliding'), uint8(Bs)); %!assert(im2col(uint16(As),[2,4],'sliding'), uint16(Bs)); - - - - -% -% $Log$ -% Revision 1.4 2007/03/23 16:14:36 adb014 -% Update the FSF address -% -% Revision 1.3 2007/01/04 23:47:43 hauberg -% Put seealso before end deftypefn -% -% Revision 1.2 2007/01/04 23:37:54 hauberg -% Minor changes in help text -% -% Revision 1.1 2006/08/20 12:59:33 hauberg -% Changed the structure to match the package system -% -% Revision 1.3 2005/09/08 02:00:17 pkienzle -% [for Bill Denney] isstr -> ischar -% -% Revision 1.2 2004/09/03 17:37:08 jmones -% Added support for int* and uint* types -% -% Revision 1.1 2004/08/18 14:39:07 jmones -% im2col and col2im added -% -%
--- a/inst/imadjust.m +++ b/inst/imadjust.m @@ -1,30 +1,26 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 1999,2000 Kai Habel <kai.habel@gmx.de> +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. -## -## -## Based on old imadjust.m (GPL): -## Copyright (C) 1999,2000 Kai Habel - +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} @var{J}= imadjust (@var{I}) -## @deftypefnx {Function File} @var{J}= imadjust (@var{I},[@var{low_in};@var{high_in}]) -## @deftypefnx {Function File} @var{J}= imadjust (@var{I},[@var{low_in};@var{high_in}],[@var{low_out};@var{high_out}]) -## @deftypefnx {Function File} @var{J}= imadjust (..., @var{gamma}) -## @deftypefnx {Function File} @var{newmap}= imadjust (@var{map}, ...) -## @deftypefnx {Function File} @var{RGB_out}= imadjust (@var{RGB}, ...) +## @deftypefn {Function File} {@var{J} =} imadjust (@var{I}) +## @deftypefnx {Function File} {@var{J} =} imadjust (@var{I},[@var{low_in};@var{high_in}]) +## @deftypefnx {Function File} {@var{J} =} imadjust (@var{I},[@var{low_in};@var{high_in}],[@var{low_out};@var{high_out}]) +## @deftypefnx {Function File} {@var{J} =} imadjust (@dots{}, @var{gamma}) +## @deftypefnx {Function File} {@var{newmap} =} imadjust (@var{map}, @dots{}) +## @deftypefnx {Function File} {@var{RGB_out} =} imadjust (@var{RGB}, @dots{}) ## Adjust image or colormap values to a specified range. ## ## @code{J=imadjust(I)} adjusts intensity image @var{I} values so that @@ -47,14 +43,14 @@ ## @var{high_out} instead of 0 and 1. A default value @code{[]} can also ## be used for this parameter, which is taken as @code{[0;1]}. ## -## @code{J=imadjust(...,gamma)} takes, in addition of 3 parameters +## @code{J=imadjust(@dots{},gamma)} takes, in addition of 3 parameters ## explained above, an extra parameter @var{gamma}, which specifies the ## shape of the mapping curve between input elements and output ## elements, which is linear (as taken if this parameter is omitted). If ## @var{gamma} is above 1, then function is weighted towards lower ## values, and if below 1, towards higher values. ## -## @code{newmap=imadjust(map,...)} applies a transformation to a +## @code{newmap=imadjust(map,@dots{})} applies a transformation to a ## colormap @var{map}, which output is @var{newmap}. This transformation ## is the same as explained above, just using a map instead of an image. ## @var{low_in}, @var{high_in}, @var{low_out}, @var{high_out} and @@ -62,7 +58,7 @@ ## for all three color components of a map; or it can be 1-by-3 ## vectors, to define unique mappings for each component. ## -## @code{RGB_out=imadjust(RGB,...)} adjust RGB image @var{RGB} (a +## @code{RGB_out=imadjust(RGB,@dots{})} adjust RGB image @var{RGB} (a ## M-by-N-by-3 array) the same way as specified in images and colormaps. ## Here too @var{low_in}, @var{high_in}, @var{low_out}, @var{high_out} and ## @var{gamma} can be scalars or 1-by-3 matrices, to specify the same @@ -95,46 +91,27 @@ ## @seealso{stretchlim, brighten} ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - ## TODO: When Octave 2.1.58 is out multiply indices if input argument is ## TODO: of class int* or uint*. -function ret = imadjust (image, in, out, gamma) +function ret = imadjust (image, in = stretchlim (image), out = [0;1], gamma = 1) if (nargin < 1 || nargin > 4) - usage ("imadjust(...) number of arguments must be between 1 and 4"); - endif - - if (nargin < 4) - gamma = 1; ## default gamma + print_usage; endif if !(ismatrix(image)) error ("imadjust(image,...) first parameter must be a image matrix or colormap"); endif - if (nargin==1) - in=stretchlim(image); ## this saturates 1% on lower and 1% on - out=[0;1]; ## higher values - endif - - if (nargin==2) - out=[0;1]; ## default out - endif - if !((ismatrix(in) || isempty(in)) && (ismatrix(out) || isempty(out)) ) - usage("imadjust(image,[low high],[bottom top],gamma)"); + print_usage; endif if (isempty(in)) in=[0;1]; ## default in endif - if (isempty(out)) - out=[0;1]; ## default out - endif - simage=size(image); if (length(simage)==3 && simage(3)==3) ## image is rgb @@ -157,13 +134,13 @@ ret=[]; ## process each color for i=1:3 - ret=horzcat(ret,__imadjust_plane__(image(:,i),in(1,i),in(2,i),out(1,i),out(2,i),gamma(i))); + ret=horzcat(ret,__imadjust_plane__(image(:,i),in(1,i),in(2,i),out(1,i),out(2,i),gamma(i))); endfor else ## image is a intensity image if( !isvector(in) || length(in)!=2 || !isvector(out) || length(out)!=2 || !isscalar(gamma) || (gamma<0) || (gamma==Inf) ) - error("imadjust: on an intensity image, in and out must be 2-by-1 and gamma a positive scalar."); + error("imadjust: on an intensity image, in and out must be 2-by-1 and gamma a positive scalar."); endif ret=__imadjust_plane__(image,in(1),in(2),out(1),out(2),gamma); endif @@ -173,7 +150,6 @@ endif endfunction - ## This does all the work. I has a plane; li and hi input low and high ## values; and lo and ho, output bottom and top values. ## Image negative is computed if ho<lo although nothing special is @@ -184,7 +160,6 @@ ret = ret + (I >= hi) .* ho; endfunction - ## Checks in, out and gamma to see if they are ok for colormap and RGB ## cases. function [in, out, gamma]=__imadjust_check_3d_args__(in, out, gamma) @@ -226,7 +201,6 @@ endfunction - # bad arguments # bad images @@ -251,16 +225,15 @@ %!# a test with input and output args %!assert(imadjust([1:100],[50;90],[-50;-30]), \ -%! [-50*ones(1,49), linspace(-50,-30,90-50+1), -30*ones(1,10)]); +%! [-50*ones(1,49), linspace(-50,-30,90-50+1), -30*ones(1,10)]); %!# a test with input and output args in a row vector (Compatibility behaviour) %!assert(imadjust([1:100],[50,90],[-50,-30]), \ -%! [-50*ones(1,49), linspace(-50,-30,90-50+1), -30*ones(1,10)]); +%! [-50*ones(1,49), linspace(-50,-30,90-50+1), -30*ones(1,10)]); %!# the previous test, "negated" %!assert(imadjust([1:100],[50;90],[-30;-50]), \ -%! [-30*ones(1,49), linspace(-30,-50,90-50+1), -50*ones(1,10)]); - +%! [-30*ones(1,49), linspace(-30,-50,90-50+1), -50*ones(1,10)]); %!shared cm,cmn %! cm=[[1:10]',[2:11]',[3:12]']; @@ -280,7 +253,7 @@ %! [[0,linspace(0,1,6),1,1,1]', \ %! [0,0,linspace(0,1,6),1,1]', \ %! [0,0,0,linspace(0,1,6),1]'] \ -%! ))(:)) < 1e-10 \ +%! ))(:)) < 1e-10 \ %! ); %!# a colormap, different input and output on each @@ -296,10 +269,9 @@ %! [[0,linspace(0,1,6),1,1,1]', \ %! [0,0,linspace(0,1,6).^2,1,1]'+1, \ %! [0,0,0,linspace(0,1,6).^3,1]'+2] \ -%! )(:))) < 1e-10 \ +%! )(:))) < 1e-10 \ %! ); - %!shared iRGB,iRGBn,oRGB %! iRGB=zeros(10,1,3); %! iRGB(:,:,1)=[1:10]'; @@ -325,7 +297,6 @@ %! t(:,:,3)+=30; %! assert(imadjust(iRGBn,[0;1],[10,20,30;11,21,31]),t); - %!# a RGB, different input on each, we need increased tolerance for this test %!assert(sum(abs((imadjust(iRGB,[2,4,6;7,9,11],[0;1]) - oRGB)(:))) < 1e-10); @@ -342,20 +313,3 @@ %! t(:,:,2)=t(:,:,2).^2+1; %! t(:,:,3)=t(:,:,3).^3+2; %! assert(sum(abs((imadjust(iRGB,[2,4,6;7,9,11],[0,1,2;1,2,3],[1,2,3]) - t)(:))) < 1e-10); - - -% -% $Log$ -% Revision 1.3 2007/03/23 16:14:37 adb014 -% Update the FSF address -% -% Revision 1.2 2007/01/04 23:47:43 hauberg -% Put seealso before end deftypefn -% -% Revision 1.1 2006/08/20 12:59:33 hauberg -% Changed the structure to match the package system -% -% Revision 1.3 2004/09/01 22:51:14 jmones -% Fully recoded: NDArray support, docs, tests, more compatible with MATLAB, changed copyright -% -%
--- a/inst/imdither.m +++ b/inst/imdither.m @@ -1,26 +1,29 @@ ## Copyright (C) 2009 Sergey Kirgizov ## -## 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 3 -## 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. - +## 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 3 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 <http://www.gnu.org/licenses/>. + ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{Y}, @var{newmap}] = } imdither (@var{img}) -## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] = } imdither (@var{img}, @ +## @deftypefn {Function File} {[@var{Y}, @var{newmap}] =} imdither (@var{img}) +## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} imdither (@var{img}, @ ## @var{colors}) -## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] = } imdither (@var{img}, @ +## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} imdither (@var{img}, @ ## @var{colors}, @var{dithtype}) -## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] = } imdither (@var{img}, @ +## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} imdither (@var{img}, @ ## @var{map}) -## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] = } imdither (@var{img}, @ +## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} imdither (@var{img}, @ ## @var{map}, @var{colors}) -## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] = } imdither(@var{img}, @ +## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} imdither(@var{img}, @ ## @var{map}, @var{colors}, @var{dithtype}) ## Reduce the number a colors of rgb or indexed image. ## @@ -48,19 +51,11 @@ ## ## @end deftypefn -function [Y,newmap] = imdither(im,p1,p2,p3) - +function [Y, newmap] = imdither (im, p1, p2, p3) colors="256"; dithtype="FloydSteinberg"; - if ( nargin < 1 ) - usage([ ... - "imdither( rgb )\n", ... - "imdither( rgb,colors )\n", ... - "imdither( rgb,colors,dithtype )\n", ... - "imdither( img,map )\n", ... - "imdither( img,map,colors )\n", ... - "imdither( img,map,colors,dithtype )\n" - ]); + if (nargin < 1) + print_usage; endif fname = [tmpnam(),".ppm"]; @@ -74,18 +69,11 @@ endif opts=["-colors ",colors;"-dither ",dithtype]; imwrite(fname,im(:,:,1),im(:,:,2),im(:,:,3),opts); - [Y,newmap]=cmunique(imread(fname)); + [Y,newmap]=cmunique(imread(fname)); delete(fname); - else + else if (nargin <= 1) - usage([ ... - "imdither( rgb )\n", ... - "imdither( rgb,colors )\n", ... - "imdither( rgb,colors,dithtype )\n", ... - "imdither( img,map )\n", ... - "imdither( img,map,colors )\n", ... - "imdither( img,map,colors,dithtype )\n" - ]); + print_usage; endif # indexed if (nargin >= 3) @@ -97,7 +85,7 @@ opts=["-colors ",colors;"-dither ",dithtype]; im (rows(p1)<=256) imwrite(fname,im,(p1+1),opts); - [Y,newmap]=cmunique(imread(fname)); + [Y,newmap]=cmunique(imread(fname)); delete(fname); endif endfunction
--- a/inst/imnoise.m +++ b/inst/imnoise.m @@ -1,17 +1,18 @@ -## Copyright (C) 2000 Paul Kienzle +## Copyright (C) 2000 Paul Kienzle <pkienzle@users.sf.net> +## Copyright (C) 2004 Stefan van der Walt <stefan@sun.ac.za> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn {Function File} {@var{B} =} imnoise (@var{A}, @var{type}) @@ -30,12 +31,10 @@ ## @end table ## @end deftypefn -## Modified: Stefan van der Walt <stefan@sun.ac.za>, 2004-02-24 - -function A = imnoise(A, stype, a, b) +function A = imnoise (A, stype, a, b) if (nargin < 2 || nargin > 4 || !ismatrix(A) || !ischar(stype)) - usage("B = imnoise(A, type, parameters, ...)"); + print_usage; endif valid = (min(A(:)) >= 0 && max(A(:)) <= 1);
--- a/inst/makelut.m +++ b/inst/makelut.m @@ -1,21 +1,21 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{lut} = } makelut (@var{fun},@var{n}) -## @deftypefnx {Function File} {@var{lut} = } makelut (@var{fun},@var{n},@var{P1},@var{P2},...) +## @deftypefn {Function File} {@var{lut} =} makelut (@var{fun}, @var{n}) +## @deftypefnx {Function File} {@var{lut} =} makelut (@var{fun}, @var{n}, @var{P1}, @var{P2}, @dots{}) ## Create a lookup table which can be used by applylut. ## ## lut = makelut(fun,n) returns a vector which can be used by applylut @@ -31,19 +31,15 @@ ## vector with its result, suitable to be used by applylut. The length ## of this vector is 2^(@var{n}^2), so 16 for 2-by-2 and 512 for 3-by-3. ## -## makelut also passes parameters @var{P1}, @var{P2}, .... to @var{fun}. +## makelut also passes parameters @var{P1}, @var{P2}, .... to @var{fun}. ## ## @seealso{applylut} ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function lut = makelut(fun, n, varargin) +function lut = makelut (fun, n, varargin) if (nargin < 2) - usage ("lut = makelut(fun, n [, ...])"); - endif - - if (n<2) + print_usage; + elseif (n < 2) error ("makelut: n should be a natural number >= 2"); endif @@ -67,6 +63,3 @@ %!assert(prod(makelut(inline('x(1,1)==1','x'),3)==[zeros(2^8,1);ones(2^8,1)])==1); # test 3-by-3 %!assert(prod(makelut(inline('x(1,1)==1','x'),4)==[zeros(2^15,1);ones(2^15,1)])==1); # test 4-by-4 %!assert(prod(makelut(inline('x(2,1)==1','x'),3)==[zeros(2^7,1);ones(2^7,1);zeros(2^7,1);ones(2^7,1)])==1); # another test for 3-by-3 - - -
--- a/inst/qtdecomp.m +++ b/inst/qtdecomp.m @@ -1,25 +1,25 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{S} = } qtdecomp (@var{I}) -## @deftypefnx {Function File} {@var{S} = } qtdecomp (@var{I},@var{threshold}) -## @deftypefnx {Function File} {@var{S} = } qtdecomp (@var{I},@var{threshold},@var{mindim}) -## @deftypefnx {Function File} {@var{S} = } qtdecomp (@var{I},@var{threshold},@var{[mindim maxdim]}) -## @deftypefnx {Function File} {@var{S} = } qtdecomp (@var{I},@var{fun}) -## @deftypefnx {Function File} {@var{S} = } qtdecomp (@var{I},@var{fun},@var{P1},@var{P2},...) +## @deftypefn {Function File} {@var{S} =} qtdecomp (@var{I}) +## @deftypefnx {Function File} {@var{S} =} qtdecomp (@var{I}, @var{threshold}) +## @deftypefnx {Function File} {@var{S} =} qtdecomp (@var{I}, @var{threshold}, @var{mindim}) +## @deftypefnx {Function File} {@var{S} =} qtdecomp (@var{I}, @var{threshold}, [@var{mindim} @var{maxdim}]) +## @deftypefnx {Function File} {@var{S} =} qtdecomp (@var{I}, @var{fun}) +## @deftypefnx {Function File} {@var{S} =} qtdecomp (@var{I}, @var{fun}, @var{P1}, @var{P2}, @dots{}) ## Performs quadtree decomposition. ## ## qtdecomp decomposes a square image @var{I} into four equal-sized @@ -67,14 +67,10 @@ ## @seealso{qtgetblk, qtsetblk} ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function S = qtdecomp(I, p1, varargin) - if (nargin<1) - usage("S=qtdecomp(I)"); - endif - - if (!ismatrix(I) || size(I,1)!=size(I,2)) +function S = qtdecomp (I, p1, varargin) + if (nargin < 1) + print_usage; + elseif (!ismatrix(I) || size(I,1)!=size(I,2)) error("qtdecomp: I should be a square matrix."); endif @@ -107,24 +103,23 @@ endif if (nargin>3) - usage("S=qtdecomp(I,threshold,mindim), \ - S=qtdecomp(I,threshold,[mindim maxdim])"); + print_usage; elseif (nargin==3) dims=varargin{1}; if (isvector(dims)&&length(dims)==2) - mindim=dims(1); - maxdim=dims(2); + mindim=dims(1); + maxdim=dims(2); elseif (isreal(dims)) - mindim=dims; + mindim=dims; else - error("qtdecomp: third parameter must be 'mindim' or '[mindim maxdim]'"); + error("qtdecomp: third parameter must be 'mindim' or '[mindim maxdim]'"); endif ## we won't check if mindim or maxdim are powers of 2. It's too ## restrictive and don't need it at all. endif elseif strcmp(typeinfo(p1),"function handle") ... - || strcmp(typeinfo(p1),"inline function") + || strcmp(typeinfo(p1),"inline function") ## function handles seem to return true to isscalar fun=p1; decision_method=2; @@ -151,12 +146,12 @@ if(initial_splits>0) divs=2^initial_splits; if (rem(curr_size,divs)!=0) - error("qtdecomp: Can't decompose I enough times to fulfill maxdim requirement."); + error("qtdecomp: Can't decompose I enough times to fulfill maxdim requirement."); endif ## update curr_size curr_size/=divs; if(curr_size<mindim) - error("qtdecomp: maxdim restriction collides with mindim restriction."); + error("qtdecomp: maxdim restriction collides with mindim restriction."); endif els=([0:divs-1]*curr_size+1).'; offsets=[kron(els,ones(divs,1)), kron(ones(divs,1),els)]; @@ -173,37 +168,37 @@ finished = true; else if (decision_method<2) - db=logical(ones(rows(offsets),1)); - for r=1:rows(offsets) - o=offsets(r,:); - fo=offsets(r,:)+curr_size-1; + db=logical(ones(rows(offsets),1)); + for r=1:rows(offsets) + o=offsets(r,:); + fo=offsets(r,:)+curr_size-1; - if(decision_method==0) - ## is everything equal? - if (all(I(o(1),o(2))==I(o(1):fo(1),o(2):fo(2)))) - db(r)=0; - endif - else - ## check threshold - t=I(o(1):fo(1),o(2):fo(2)); - t=t(:); - if ((max(t)-min(t))<=threshold) - db(r)=0; - endif - endif - endfor + if(decision_method==0) + ## is everything equal? + if (all(I(o(1),o(2))==I(o(1):fo(1),o(2):fo(2)))) + db(r)=0; + endif + else + ## check threshold + t=I(o(1):fo(1),o(2):fo(2)); + t=t(:); + if ((max(t)-min(t))<=threshold) + db(r)=0; + endif + endif + endfor elseif(decision_method==2) - ## function handle decision method - ## build blocks - b=zeros(curr_size,curr_size,rows(offsets)); - rbc=offsets(:,1:2)+curr_size-1; - for r=1:rows(offsets) - b(:,:,r)=I(offsets(r,1):rbc(r,1),offsets(r,2):rbc(r,2)); - endfor + ## function handle decision method + ## build blocks + b=zeros(curr_size,curr_size,rows(offsets)); + rbc=offsets(:,1:2)+curr_size-1; + for r=1:rows(offsets) + b(:,:,r)=I(offsets(r,1):rbc(r,1),offsets(r,2):rbc(r,2)); + endfor - db=feval(fun, b, varargin{:}); + db=feval(fun, b, varargin{:}); else - error("qtdecomp: execution shouldn't reach here. Please report this as a bug."); + error("qtdecomp: execution shouldn't reach here. Please report this as a bug."); endif ## Add blocks that won't divide to results @@ -224,12 +219,10 @@ S=sparse(res(:,1),res(:,2),res(:,3),size(I,1),size(I,2)); endfunction - %!demo %! full(qtdecomp(eye(8))) %! %It finds 2 big blocks of 0 and it decomposes further where 0 and 1 are mixed. - %!# Test if odd-sized limits split %!assert(full(qtdecomp(eye(5))), reshape([5,zeros(1,24)],5,5)); %!assert(full(qtdecomp(eye(6))), repmat(reshape([3,zeros(1,8)],3,3),2,2)); @@ -245,9 +238,9 @@ %! 3, 6, 3, 1,58,53,67,65; %! 3, 6, 3, 1,58,53,67,65; %! 3, 6, 3, 1,58,53,67,65; -%! 23,42,42,42,99,99,99,99; -%! 27,42,42,42,99,99,99,99; -%! 23,22,26,25,99,99,99,99; +%! 23,42,42,42,99,99,99,99; +%! 27,42,42,42,99,99,99,99; +%! 23,22,26,25,99,99,99,99; %! 22,22,24,22,99,99,99,99]; %! B2=[2,0;0,0]; %! B4=zeros(4); B4(1,1)=4; @@ -282,60 +275,14 @@ %!test %!# no params %! first_eq=inline("(A(1,1,:)!=(54*ones(1,1,size(A,3))))(:)","A"); -%! assert(full(qtdecomp(A,first_eq)),[ones(4),B4;ones(4,8)]); +%! assert(full(qtdecomp(A,first_eq)),[ones(4),B4;ones(4,8)]); %!test %!# 1 param %! first_eq=inline("(A(1,1,:)!=(c*ones(1,1,size(A,3))))(:)","A","c"); -%! assert(full(qtdecomp(A,first_eq,54)),[ones(4),B4;ones(4,8)]); +%! assert(full(qtdecomp(A,first_eq,54)),[ones(4),B4;ones(4,8)]); %!test %!# 3 params %! first_eq=inline("(A(1,1,:)!=((c1+c2+c3)*ones(1,1,size(A,3))))(:)","A","c1","c2","c3"); -%! assert(full(qtdecomp(A,first_eq,4,40,10)),[ones(4),B4;ones(4,8)]); - - - -% -% $Log$ -% Revision 1.5 2007/03/23 16:14:37 adb014 -% Update the FSF address -% -% Revision 1.4 2007/01/04 23:50:47 hauberg -% Put seealso before end deftypefn -% -% Revision 1.3 2007/01/04 23:41:47 hauberg -% Minor changes in help text -% -% Revision 1.2 2006/10/09 19:58:09 adb014 -% Remove dependency on miscellaneous transpose function. Simplify tests and add function handle tests -% -% Revision 1.1 2006/08/20 12:59:35 hauberg -% Changed the structure to match the package system -% -% Revision 1.8 2006/01/03 02:09:15 pkienzle -% Reorder tests so that shared variables are displayed unless relevant. -% -% Revision 1.7 2006/01/02 22:05:06 pkienzle -% Reduce number of shared variables in tests -% -% Revision 1.6 2004/09/09 19:36:35 jmones -% all_va_args -> varargin{:}. Now works on 2.1.58 -% -% Revision 1.5 2004/09/08 14:07:22 pkienzle -% Fix test for 'inline function' -% -% Revision 1.4 2004/08/11 19:52:41 jmones -% qtsetblk added -% -% Revision 1.3 2004/08/11 00:05:21 jmones -% seealso qtgetblk added to doc -% -% Revision 1.2 2004/08/10 00:19:42 jmones -% Corrected misleading comment. -% -% Revision 1.1 2004/08/09 01:48:54 jmones -% Added qtdecomp: quadtree decomposition -% -% - +%! assert(full(qtdecomp(A,first_eq,4,40,10)),[ones(4),B4;ones(4,8)]);
--- a/inst/qtgetblk.m +++ b/inst/qtgetblk.m @@ -1,22 +1,22 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{vals}] = } qtgetblk (@var{I},@var{S},@var{dim}) -## @deftypefnx {Function File} {[@var{vals},@var{idx}] = } qtgetblk (@var{I},@var{S},@var{dim}) -## @deftypefnx {Function File} {[@var{vals},@var{r},@var{c}] = } qtgetblk (@var{I},@var{S},@var{dim}) +## @deftypefn {Function File} {[@var{vals}] =} qtgetblk (@var{I}, @var{S}, @var{dim}) +## @deftypefnx {Function File} {[@var{vals},@var{idx}] =} qtgetblk (@var{I}, @var{S}, @var{dim}) +## @deftypefnx {Function File} {[@var{vals},@var{r},@var{c}] =} qtgetblk (@var{I}, @var{S}, @var{dim}) ## Obtain block values from a quadtree decomposition. ## ## [vals]=qtgetblk(I,S,dim) returns a dim-by-dim-by-k array in @@ -36,14 +36,9 @@ ## @seealso{qtdecomp, qtsetblk} ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - function [varargout] = qtgetblk(I, S, dim) - if (nargin!=3) - usage("[vals,r,c]=qtgetblk(I,S,dim), [vals,idx]=qtgetblk(I,S,dim)"); - endif - if (nargout>3) - usage("[vals,r,c]=qtgetblk(I,S,dim), [vals,idx]=qtgetblk(I,S,dim)"); + if (nargin != 3 || nargout > 3) + print_usage; endif ## get blocks @@ -77,7 +72,6 @@ endif endfunction - %!demo %! [vals,r,c]=qtgetblk(eye(4),qtdecomp(eye(4)),2) %! % Returns 2 blocks, at [1,3] and [3,1] (2*2 zeros blocks) @@ -87,9 +81,9 @@ %! 3, 6, 3, 1,58,53,67,65; %! 3, 6, 3, 1,58,53,67,65; %! 3, 6, 3, 1,58,53,67,65; -%! 23,42,42,42,99,99,99,99; -%! 27,42,42,42,99,99,99,99; -%! 23,22,26,25,99,99,99,99; +%! 23,42,42,42,99,99,99,99; +%! 27,42,42,42,99,99,99,99; +%! 23,22,26,25,99,99,99,99; %! 22,22,24,22,99,99,99,99]; %! S=qtdecomp(A,10); @@ -105,7 +99,6 @@ %! R=[]; %! assert(va,R); - %!test %! [va]=qtgetblk(A,S,4); %! [vb,r,c]=qtgetblk(A,S,4); @@ -138,25 +131,3 @@ %! R(:,:,6)=A(1:2,7:8); %! R(:,:,7)=A(3:4,7:8); %! assert(va,R); - -% -% $Log$ -% Revision 1.4 2007/03/23 16:14:37 adb014 -% Update the FSF address -% -% Revision 1.3 2007/01/04 23:50:47 hauberg -% Put seealso before end deftypefn -% -% Revision 1.2 2007/01/04 23:41:47 hauberg -% Minor changes in help text -% -% Revision 1.1 2006/08/20 12:59:35 hauberg -% Changed the structure to match the package system -% -% Revision 1.3 2006/01/02 20:53:42 pkienzle -% Reduce number of shared variables in tests -% -% Revision 1.2 2004/08/11 19:52:41 jmones -% qtsetblk added -% -%
--- a/inst/qtsetblk.m +++ b/inst/qtsetblk.m @@ -1,20 +1,20 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{J} = } qtsetblk (@var{I},@var{S},@var{dim},@var{vals}) +## @deftypefn {Function File} {@var{J} =} qtsetblk (@var{I}, @var{S}, @var{dim}, @var{vals}) ## Set block values in a quadtree decomposition. ## ## J=qtsetblk(I,S,dim,vals) sets all the @var{dim}-by-@var{dim} blocks @@ -25,11 +25,9 @@ ## @seealso{qtdecomp, qtgetblk} ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function J = qtsetblk(I, S, dim, vals) - if (nargin!=4) - usage("J=qtsetblk(I,S,dim,vals)"); +function J = qtsetblk (I, S, dim, vals) + if (nargin != 4) + print_usage; endif ## get blocks @@ -47,14 +45,12 @@ ie=ii+dim-1; je=ji+dim-1; - J=I; for b=1:length(idx) J(ii(b):ie(b),ji(b):je(b))=vals(:,:,b); endfor endfunction - %!demo %! J=qtsetblk(eye(4),qtdecomp(eye(4)),2,ones(2,2,2)) %! % Sets upper-right and lower-left blocks of 2*2 zeros to ones @@ -64,11 +60,11 @@ %! 3, 6, 3, 1,58,53,67,65; %! 3, 6, 3, 1,58,53,67,65; %! 3, 6, 3, 1,58,53,67,65; -%! 23,42,42,42,99,99,99,99; -%! 27,42,42,42,99,99,99,99; -%! 23,22,26,25,99,99,99,99; +%! 23,42,42,42,99,99,99,99; +%! 27,42,42,42,99,99,99,99; +%! 23,22,26,25,99,99,99,99; %! 22,22,24,22,99,99,99,99]; -%! S=qtdecomp(A,10); +%! S = qtdecomp (A, 10); %!test %! R=A; @@ -90,24 +86,3 @@ %! R=A; %! R(5:6,1:2)=10; %! assert(qtsetblk(A,S,1,ones(1,1,4)*10),R); - - - -% -% $Log$ -% Revision 1.4 2007/03/23 16:14:37 adb014 -% Update the FSF address -% -% Revision 1.3 2007/01/04 23:50:47 hauberg -% Put seealso before end deftypefn -% -% Revision 1.2 2007/01/04 23:41:47 hauberg -% Minor changes in help text -% -% Revision 1.1 2006/08/20 12:59:35 hauberg -% Changed the structure to match the package system -% -% Revision 1.1 2004/08/11 19:52:41 jmones -% qtsetblk added -% -%
--- a/inst/roicolor.m +++ b/inst/roicolor.m @@ -1,20 +1,20 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{BW} = } roicolor (@var{A},@var{low},@var{high}) +## @deftypefn {Function File} {@var{BW} =} roicolor (@var{A}, @var{low}, @var{high}) ## @deftypefnx {Function File} {@var{BW} = } roicolor (@var{A},@var{v}) ## Select a Region Of Interest of an image based on color. ## @@ -28,11 +28,9 @@ ## pixels that match values in @var{v}. ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function BW = roicolor(A, p1, p2) +function BW = roicolor (A, p1, p2) if (nargin < 2 || nargin > 3) - usage("BW = roicolor(A, low, high), BW = roicolor(A, v)"); + print_usage; endif if (nargin == 2) @@ -58,22 +56,3 @@ %!assert(roicolor([1:10],2,4),logical([0,1,1,1,zeros(1,6)])); %!assert(roicolor([1,2;3,4],3,3),logical([0,0;1,0])); %!assert(roicolor([1,2;3,4],[1,4]),logical([1,0;0,1])); - -% -% $Log$ -% Revision 1.2 2007/03/23 16:14:37 adb014 -% Update the FSF address -% -% Revision 1.1 2006/08/20 12:59:35 hauberg -% Changed the structure to match the package system -% -% Revision 1.3 2004/09/15 17:54:59 pkienzle -% test that data type matches during assert -% -% Revision 1.2 2004/08/11 15:04:59 pkienzle -% Convert dos line endings to unix line endings -% -% Revision 1.1 2004/08/08 21:02:44 jmones -% Add roicolor function (selects ROI based on color) -% -%
--- a/inst/uintlut.m +++ b/inst/uintlut.m @@ -1,39 +1,37 @@ -## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> ## -## 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 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 3 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. +## 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 <http://www.gnu.org/licenses/>. +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{B} = } uintlut (@var{A},@var{LUT}) +## @deftypefn {Function File} {@var{B} =} uintlut (@var{A}, @var{LUT}) ## Computes matrix B by using A as an index to lookup table LUT. ## ## B = uintlut(A, LUT) calculates a matrix B by using @var{LUT} as a ## lookup table indexed by values in @var{A}. ## -## B class is the same as @var{LUT}. +## B class is the same as @var{LUT}. ## @end deftypefn -## Author: Josep Mones i Teixidor <jmones@puntbarra.com> - -function B = uintlut(A, LUT) +function B = uintlut (A, LUT) if (nargin != 2) - usage("B = uintlut(A, LUT)"); + print_usage; endif ## We convert indexing array A to double since even CVS version of ## Octave is unable to use non-double arrays as indexing types. This ## won't be needed in the future eventually. - B=LUT(double(A)); + B = LUT(double(A)); endfunction %!demo @@ -44,19 +42,3 @@ %!assert(uintlut(uint16([1,2,3,4]),uint16([255:-1:0])), uint16([255:-1:252])); %!assert(uintlut(uint32([1,2,3,4]),uint32([255:-1:0])), uint32([255:-1:252])); %!assert(uintlut(uint64([1,2,3,4]),uint64([255:-1:0])), uint64([255:-1:252])); - -% -% $Log$ -% Revision 1.2 2007/03/23 16:14:38 adb014 -% Update the FSF address -% -% Revision 1.1 2006/08/20 12:59:36 hauberg -% Changed the structure to match the package system -% -% Revision 1.2 2004/08/11 15:04:59 pkienzle -% Convert dos line endings to unix line endings -% -% Revision 1.1 2004/08/08 21:20:25 jmones -% uintlut and padarray functions added -% -%