From: <ha...@us...> - 2009-05-14 17:19:15
|
Revision: 5823 http://octave.svn.sourceforge.net/octave/?rev=5823&view=rev Author: hauberg Date: 2009-05-14 17:19:06 +0000 (Thu, 14 May 2009) Log Message: ----------- Minor demo improvements Modified Paths: -------------- trunk/octave-forge/main/image/inst/applylut.m trunk/octave-forge/main/image/inst/bestblk.m Modified: trunk/octave-forge/main/image/inst/applylut.m =================================================================== --- trunk/octave-forge/main/image/inst/applylut.m 2009-05-14 17:09:06 UTC (rev 5822) +++ trunk/octave-forge/main/image/inst/applylut.m 2009-05-14 17:19:06 UTC (rev 5823) @@ -45,10 +45,11 @@ endfunction %!demo -%! lut=makelut(inline('sum(x(:))>=3','x'), 3); -%! applylut(eye(5),lut) -%! % everything should be 0 despite a diagonal which -%! % doesn't reach borders. +%! 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. %!assert(prod(applylut(eye(3),makelut(inline('x(1,1)==1','x'),2))==eye(3))==1); % 2-by-2 test Modified: trunk/octave-forge/main/image/inst/bestblk.m =================================================================== --- trunk/octave-forge/main/image/inst/bestblk.m 2009-05-14 17:09:06 UTC (rev 5822) +++ trunk/octave-forge/main/image/inst/bestblk.m 2009-05-14 17:19:06 UTC (rev 5823) @@ -95,8 +95,8 @@ endfunction %!demo -%! siz=bestblk([200;10],50) -%! # Best block is [20,10] +%! siz = bestblk ([200; 10], 50); +%! disp (siz) %!assert(bestblk([300;100],150),[30;100]); %!assert(bestblk([256,128],17),[16;16]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ha...@us...> - 2009-10-26 10:27:57
|
Revision: 6390 http://octave.svn.sourceforge.net/octave/?rev=6390&view=rev Author: hauberg Date: 2009-10-26 10:27:47 +0000 (Mon, 26 Oct 2009) Log Message: ----------- Add missing 'swap' function Modified Paths: -------------- trunk/octave-forge/main/image/inst/bwmorph.m trunk/octave-forge/main/image/inst/imremap.m Modified: trunk/octave-forge/main/image/inst/bwmorph.m =================================================================== --- trunk/octave-forge/main/image/inst/bwmorph.m 2009-10-26 10:17:20 UTC (rev 6389) +++ trunk/octave-forge/main/image/inst/bwmorph.m 2009-10-26 10:27:47 UTC (rev 6390) @@ -562,6 +562,8 @@ endfunction +function [b, a] = swap (a, b) +endfunction %!demo %! bwmorph(ones(11),'shrink', Inf) Modified: trunk/octave-forge/main/image/inst/imremap.m =================================================================== --- trunk/octave-forge/main/image/inst/imremap.m 2009-10-26 10:17:20 UTC (rev 6389) +++ trunk/octave-forge/main/image/inst/imremap.m 2009-10-26 10:27:47 UTC (rev 6390) @@ -66,7 +66,7 @@ error("imremap: XI and YI must be matrices of the same size"); endif - if (!any(strcmpi(interp, {"nearest", "linear", "bilinear", "cubic", "bicubic"}))) + if (!any(strcmpi(interp, {"nearest", "linear", "bilinear", "cubic", "bicubic", "spline"}))) error("imremap: unsupported interpolation method"); endif if (any(strcmpi(interp, {"bilinear", "bicubic"}))) @@ -100,11 +100,11 @@ endfunction function [warped, valid] = grayinterp(im, XI, YI, interp, extrapval) - if (strcmp(interp, "cubic")) - warped = graybicubic(double(im), XI, YI, NA); - else + %if (strcmp(interp, "cubic")) + % warped = graybicubic(double(im), XI, YI, NA); + %else warped = interp2(double(im), XI, YI, interp, NA); - endif + %endif valid = !isna(warped); warped(!valid) = extrapval; endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2010-01-03 19:11:39
|
Revision: 6694 http://octave.svn.sourceforge.net/octave/?rev=6694&view=rev Author: thomas-weber Date: 2010-01-03 19:11:27 +0000 (Sun, 03 Jan 2010) Log Message: ----------- Replace deprecated 'spfind' Modified Paths: -------------- trunk/octave-forge/main/image/inst/qtgetblk.m trunk/octave-forge/main/image/inst/qtsetblk.m Modified: trunk/octave-forge/main/image/inst/qtgetblk.m =================================================================== --- trunk/octave-forge/main/image/inst/qtgetblk.m 2010-01-03 18:26:38 UTC (rev 6693) +++ trunk/octave-forge/main/image/inst/qtgetblk.m 2010-01-03 19:11:27 UTC (rev 6694) @@ -47,7 +47,7 @@ endif ## get blocks - [i,j,v]=spfind(S); + [i,j,v]=find(S); ## filter the ones which match dim idx=find(v==dim); Modified: trunk/octave-forge/main/image/inst/qtsetblk.m =================================================================== --- trunk/octave-forge/main/image/inst/qtsetblk.m 2010-01-03 18:26:38 UTC (rev 6693) +++ trunk/octave-forge/main/image/inst/qtsetblk.m 2010-01-03 19:11:27 UTC (rev 6694) @@ -33,7 +33,7 @@ endif ## get blocks - [ii,ji,v]=spfind(S); + [ii,ji,v]=find(S); ## filter the ones which match dim idx=find(v==dim); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ha...@us...> - 2010-03-12 22:58:33
|
Revision: 7059 http://octave.svn.sourceforge.net/octave/?rev=7059&view=rev Author: hauberg Date: 2010-03-12 22:58:27 +0000 (Fri, 12 Mar 2010) Log Message: ----------- Change defaults to match Matlab Modified Paths: -------------- trunk/octave-forge/main/image/inst/imresize.m trunk/octave-forge/main/image/inst/imrotate.m Modified: trunk/octave-forge/main/image/inst/imresize.m =================================================================== --- trunk/octave-forge/main/image/inst/imresize.m 2010-03-12 15:07:24 UTC (rev 7058) +++ trunk/octave-forge/main/image/inst/imresize.m 2010-03-12 22:58:27 UTC (rev 7059) @@ -15,7 +15,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} @var{B}= imresize (@var{A}, @var{m}) -## Scales the image @var{A} by a factor @var{m} using nearest neighbour +## Scales the image @var{A} by a factor @var{m} using bicubic neighbour ## interpolation. If @var{m} is less than 1 the image size will be reduced, ## and if @var{m} is greater than 1 the image will be enlarged. If the image ## is being enlarged the it will be convolved with a 11x11 Gaussian FIR filter @@ -48,7 +48,7 @@ ## @seealso{imremap, imrotate, interp2} ## @end deftypefn -function ret = imresize(im, m, interp = "nearest", filter = 11) +function ret = imresize(im, m, interp = "bicubic", filter = 11) if (nargin < 2) error("imresize: not enough input arguments"); endif Modified: trunk/octave-forge/main/image/inst/imrotate.m =================================================================== --- trunk/octave-forge/main/image/inst/imrotate.m 2010-03-12 15:07:24 UTC (rev 7058) +++ trunk/octave-forge/main/image/inst/imrotate.m 2010-03-12 22:58:27 UTC (rev 7059) @@ -25,8 +25,8 @@ ## ## @var{method} ## @itemize @w -## @item "nearest" neighbor: fast, but produces aliasing effects. -## @item "bilinear" interpolation: does anti-aliasing, but is slightly slower (default). +## @item "nearest" neighbor: fast, but produces aliasing effects (default). +## @item "bilinear" interpolation: does anti-aliasing, but is slightly slower. ## @item "bicubic" interpolation: does anti-aliasing, preserves edges better than bilinear interpolation, but gray levels may slightly overshoot at sharp edges. This is probably the best method for most purposes, but also the slowest. ## @item "Fourier" uses Fourier interpolation, decomposing the rotation matrix into 3 shears. This method often results in different artifacts than homography-based methods. Instead of slightly blurry edges, this method can result in ringing artifacts (little waves near high-contrast edges). However, Fourier interpolation is better at maintaining the image information, so that unrotating will result in an image closer to the original than the other methods. ## @end itemize @@ -58,7 +58,7 @@ ## Created: 2004-10-18 ## Version: 0.7 -function [imgPost, H, valid] = imrotate(imgPre, thetaDeg, interp="bilinear", bbox="loose", extrapval=NA) +function [imgPost, H, valid] = imrotate(imgPre, thetaDeg, interp="nearest", bbox="loose", extrapval=NA) ## Check input if (nargin < 2) error("imrotate: not enough input arguments"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-04-14 00:49:12
|
Revision: 8211 http://octave.svn.sourceforge.net/octave/?rev=8211&view=rev Author: carandraug Date: 2011-04-14 00:49:06 +0000 (Thu, 14 Apr 2011) Log Message: ----------- Added checks if image and SE have the same class Modified Paths: -------------- trunk/octave-forge/main/image/inst/imdilate.m trunk/octave-forge/main/image/inst/imerode.m Modified: trunk/octave-forge/main/image/inst/imdilate.m =================================================================== --- trunk/octave-forge/main/image/inst/imdilate.m 2011-04-14 00:45:01 UTC (rev 8210) +++ trunk/octave-forge/main/image/inst/imdilate.m 2011-04-14 00:49:06 UTC (rev 8211) @@ -15,8 +15,11 @@ ## -*- texinfo -*- ## @deftypefn {Function File} @var{B} = imdilate (@var{A}, @var{se}) ## Perform morphological dilation on a given image. +## ## The image @var{A} must be a grayscale or binary image, and @var{se} must be a -## structuring element. +## structuring element. Both must have the same class, e.g., if @var{A} is a +## logical matrix, @var{se} must also be logical. +## ## @seealso{imerode, imopen, imclose} ## @end deftypefn @@ -27,9 +30,10 @@ endif if (!ismatrix(im) || !isreal(im)) error("imdilate: first input argument must be a real matrix"); - endif - if (!ismatrix(se) || !isreal(se)) + elseif (!ismatrix(se) || !isreal(se)) error("imdilate: second input argument must be a real matrix"); + elseif ( !strcmp(class(im), class(se)) ) + error("imdilate: image and structuring element must have the same class"); endif ## Perform filtering Modified: trunk/octave-forge/main/image/inst/imerode.m =================================================================== --- trunk/octave-forge/main/image/inst/imerode.m 2011-04-14 00:45:01 UTC (rev 8210) +++ trunk/octave-forge/main/image/inst/imerode.m 2011-04-14 00:49:06 UTC (rev 8211) @@ -15,8 +15,11 @@ ## -*- texinfo -*- ## @deftypefn {Function File} @var{B} = imerode (@var{A}, @var{se}) ## Perform morphological erosion on a given image. +## ## The image @var{A} must be a grayscale or binary image, and @var{se} must be a -## structuring element. +## structuring element. Both must have the same class, e.g., if @var{A} is a +## logical matrix, @var{se} must also be logical. +## ## @seealso{imdilate, imopen, imclose} ## @end deftypefn @@ -27,9 +30,10 @@ endif if (!ismatrix(im) || !isreal(im)) error("imerode: first input argument must be a real matrix"); - endif - if (!ismatrix(se) || !isreal(se)) + elseif (!ismatrix(se) || !isreal(se)) error("imerode: second input argument must be a real matrix"); + elseif ( !strcmp(class(im), class(se)) ) + error("imerode: image and structuring element must have the same class"); endif ## Perform filtering This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-10-31 03:57:43
|
Revision: 8893 http://octave.svn.sourceforge.net/octave/?rev=8893&view=rev Author: carandraug Date: 2011-10-31 03:57:36 +0000 (Mon, 31 Oct 2011) Log Message: ----------- dilate, erode: marked as deprecated in favour of imerode and imdilate Modified Paths: -------------- trunk/octave-forge/main/image/inst/dilate.m trunk/octave-forge/main/image/inst/erode.m Modified: trunk/octave-forge/main/image/inst/dilate.m =================================================================== --- trunk/octave-forge/main/image/inst/dilate.m 2011-10-31 03:03:26 UTC (rev 8892) +++ trunk/octave-forge/main/image/inst/dilate.m 2011-10-31 03:57:36 UTC (rev 8893) @@ -42,6 +42,8 @@ ## Author: Josep Mones i Teixidor <jm...@pu...> 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"); + alg='spatial'; n=1; if (nargin < 1 || nargin > 4) Modified: trunk/octave-forge/main/image/inst/erode.m =================================================================== --- trunk/octave-forge/main/image/inst/erode.m 2011-10-31 03:03:26 UTC (rev 8892) +++ trunk/octave-forge/main/image/inst/erode.m 2011-10-31 03:57:36 UTC (rev 8893) @@ -42,6 +42,8 @@ ## Author: Josep Mones i Teixidor <jm...@pu...> 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"); + alg='spatial'; n=1; if (nargin < 1 || nargin > 4) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-10-31 03:59:24
|
Revision: 8894 http://octave.svn.sourceforge.net/octave/?rev=8894&view=rev Author: carandraug Date: 2011-10-31 03:59:16 +0000 (Mon, 31 Oct 2011) Log Message: ----------- imerode, imdilate: copied tests, demo and exra help text from the now deprecated dilate and erode functions Modified Paths: -------------- trunk/octave-forge/main/image/inst/imdilate.m trunk/octave-forge/main/image/inst/imerode.m Modified: trunk/octave-forge/main/image/inst/imdilate.m =================================================================== --- trunk/octave-forge/main/image/inst/imdilate.m 2011-10-31 03:57:36 UTC (rev 8893) +++ trunk/octave-forge/main/image/inst/imdilate.m 2011-10-31 03:59:16 UTC (rev 8894) @@ -1,5 +1,5 @@ -## Copyright (C) 2004 Josep Mones i Teixidor <jm...@pu...> -## Copyright (C) 2008 Soren Hauberg +## Copyright (C) 2004 Josep Mones i Teixidor <jm...@pu...> +## Copyright (C) 2008 Soren Hauberg <so...@ha...> ## Copyright (C) 2010 Carnë Draug <car...@gm...> ## ## This program is free software; you can redistribute it and/or @@ -13,13 +13,20 @@ ## GNU General Public License for more details. ## -*- texinfo -*- -## @deftypefn {Function File} @var{B} = imdilate (@var{A}, @var{se}) +## @deftypefn {Function File} {@var{B} =} imdilate (@var{A}, @var{se}) ## Perform morphological dilation on a given image. ## -## The image @var{A} must be a grayscale or binary image, and @var{se} must be a +## The image @var{A} must be a grayscale or binary image, and @var{se} a ## structuring element. Both must have the same class, e.g., if @var{A} is a -## logical matrix, @var{se} must also be logical. +## logical matrix, @var{se} must also be logical. Note that the erosion +## algorithm is different for each class, being much faster for logical +## matrices. As such, if you have a binary matrix, you should use @code{logical} +## first. This will also reduce the memory usage of your code. ## +## The center of @var{SE} is calculated using floor((size(@var{SE})+1)/2). +## +## Pixels outside the image are considered to be 0. +## ## @seealso{imerode, imopen, imclose} ## @end deftypefn @@ -49,3 +56,11 @@ endif endfunction + +%!demo +%! imdilate(eye(5),ones(2,2)) +%! % returns a thick diagonal. + +%!assert(imdilate(eye(3),[1])==eye(3)); # using [1] as a mask returns the same value +%!assert(imdilate(eye(3),[1,0,0])==[0,0,0;1,0,0;0,1,0]); # check if it works with non-symmetric SE +%!assert(imdilate(eye(5),[1,0,0,0])==[0,0,0,0,0;1,0,0,0,0;0,1,0,0,0;0,0,1,0,0;0,0,0,1,0]); # test if center is correctly calculated on even masks Modified: trunk/octave-forge/main/image/inst/imerode.m =================================================================== --- trunk/octave-forge/main/image/inst/imerode.m 2011-10-31 03:57:36 UTC (rev 8893) +++ trunk/octave-forge/main/image/inst/imerode.m 2011-10-31 03:59:16 UTC (rev 8894) @@ -1,5 +1,5 @@ -## Copyright (C) 2004 Josep Mones i Teixidor <jm...@pu...> -## Copyright (C) 2008 Soren Hauberg +## Copyright (C) 2004 Josep Mones i Teixidor <jm...@pu...> +## Copyright (C) 2008 Soren Hauberg <so...@ha...> ## Copyright (C) 2011 Carnë Draug <car...@gm...> ## ## This program is free software; you can redistribute it and/or @@ -13,13 +13,20 @@ ## GNU General Public License for more details. ## -*- texinfo -*- -## @deftypefn {Function File} @var{B} = imerode (@var{A}, @var{se}) +## @deftypefn {Function File} {@var{B} =} imerode (@var{A}, @var{se}) ## Perform morphological erosion on a given image. ## -## The image @var{A} must be a grayscale or binary image, and @var{se} must be a +## The image @var{A} must be a grayscale or binary image, and @var{se} a ## structuring element. Both must have the same class, e.g., if @var{A} is a -## logical matrix, @var{se} must also be logical. +## logical matrix, @var{se} must also be logical. Note that the erosion +## algorithm is different for each class, being much faster for logical +## matrices. As such, if you have a binary matrix, you should use @code{logical} +## first. This will also reduce the memory usage of your code. ## +## The center of @var{SE} is calculated using floor((size(@var{SE})+1)/2). +## +## Pixels outside the image are considered to be 0. +## ## @seealso{imdilate, imopen, imclose} ## @end deftypefn @@ -46,3 +53,10 @@ endif endfunction + +%!demo +%! imerode(ones(5,5),ones(3,3)) +%! % creates a zeros border around ones. + +%!assert(imerode(eye(3),[1])==eye(3)); # using [1] as a mask returns the same value +%!assert(imerode([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]); # check if it works with non-symmetric SE This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-11-02 14:41:36
|
Revision: 8927 http://octave.svn.sourceforge.net/octave/?rev=8927&view=rev Author: carandraug Date: 2011-11-02 14:41:30 +0000 (Wed, 02 Nov 2011) Log Message: ----------- imbothat: new function for image package and modified imtophat to use it Modified Paths: -------------- trunk/octave-forge/main/image/inst/imtophat.m Added Paths: ----------- trunk/octave-forge/main/image/inst/imbothat.m Added: trunk/octave-forge/main/image/inst/imbothat.m =================================================================== --- trunk/octave-forge/main/image/inst/imbothat.m (rev 0) +++ trunk/octave-forge/main/image/inst/imbothat.m 2011-11-02 14:41:30 UTC (rev 8927) @@ -0,0 +1,52 @@ +## Copyright (C) 2005 Carvalho-Mariel +## Copyright (C) 2010-2011 Carnë Draug <car...@gm...> +## +## 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. + +## -*- texinfo -*- +## @deftypefn {Function File} @var{B} = imbothat (@var{A}, @var{se}) +## Perform morphological bottom hat filtering. +## +## The image @var{A} must be a grayscale or binary image, and @var{se} must be a +## structuring element. Both must have the same class, e.g., if @var{A} is a +## logical matrix, @var{se} must also be logical. +## +## A bottom-hat transform is also known as 'black', or 'closing', top-hat +## transform. +## +## @seealso{imerode, imdilate, imopen, imclose, imtophat, mmgradm} +## @end deftypefn + +function retval = imbothat (im, se) + + ## Checkinput + if (nargin <=1 || nargin > 3) + print_usage(); + endif + if (!ismatrix(im) || !isreal(im)) + error("imtophat: first input argument must be a real matrix"); + elseif (!ismatrix(se) || !isreal(se)) + error("imtophat: second input argument must be a real matrix"); + elseif ( !strcmp(class(im), class(se)) ) + error("imtophat: image and structuring element must have the same class"); + endif + + ## Perform filtering + ## Note that in case that the transform is to applied to a logical image, + ## subtraction must be handled in a different way (x & !y) instead of (x - y) + ## or it will return a double precision matrix + if (islogical(im)) + retval = imclose(im, se) & !im; + else + retval = imclose(im, se) - im; + endif + +endfunction Modified: trunk/octave-forge/main/image/inst/imtophat.m =================================================================== --- trunk/octave-forge/main/image/inst/imtophat.m 2011-11-02 02:58:54 UTC (rev 8926) +++ trunk/octave-forge/main/image/inst/imtophat.m 2011-11-02 14:41:30 UTC (rev 8927) @@ -1,5 +1,5 @@ ## Copyright (C) 2005 Carvalho-Mariel -## Copyright (C) 2010 Carnë Draug <car...@gm...> +## Copyright (C) 2010-2011 Carnë Draug <car...@gm...> ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License @@ -26,10 +26,13 @@ ## or @code{black}. If @var{type} is not specified, it performs a white top-hat ## transform. ## -## @seealso{imerode, imdilate, imopen, imclose, mmgradm} +## A 'black', or 'closing', top-hat transform is also known as bottom-hat +## transform and so that is the same @code{imbothat}. +## +## @seealso{imerode, imdilate, imopen, imclose, imbothat, mmgradm} ## @end deftypefn -function retval = imtophat(im, se, trans) +function retval = imtophat (im, se, trans) ## Checkinput if (nargin <=1 || nargin > 3) @@ -56,11 +59,7 @@ retval = im - imopen(im, se); endif elseif ( strcmpi(trans, "black") || strcmpi(trans, "close") ) - if (islogical(im)) - retval = imclose(im, se) & !im; - else - retval = imclose(im, se) - im; - endif + retval = imbothat (im, se); else error ("Unexpected type of top-hat transform"); endif @@ -77,5 +76,3 @@ %! result = imtophat((I), (se)); %! expected = [0 0 1; 0 0 1; 1 1 1]; %! assert(expected, result); - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-11-02 14:58:42
|
Revision: 8929 http://octave.svn.sourceforge.net/octave/?rev=8929&view=rev Author: carandraug Date: 2011-11-02 14:58:36 +0000 (Wed, 02 Nov 2011) Log Message: ----------- image package: functions using the black/close option of imtophat, now use imbothat Modified Paths: -------------- trunk/octave-forge/main/image/inst/bwmorph.m trunk/octave-forge/main/image/inst/mmgradm.m Modified: trunk/octave-forge/main/image/inst/bwmorph.m =================================================================== --- trunk/octave-forge/main/image/inst/bwmorph.m 2011-11-02 14:57:38 UTC (rev 8928) +++ trunk/octave-forge/main/image/inst/bwmorph.m 2011-11-02 14:58:36 UTC (rev 8929) @@ -184,7 +184,7 @@ ## W. K. Pratt, "Digital Image Processing" ## Gonzalez and Woods, "Digital Image Processing" ## -## @seealso{imdilate, imerode, imtophat, makelut, applylut} +## @seealso{imdilate, imerode, imtophat, imbothat, makelut, applylut} ## @end deftypefn @@ -215,7 +215,7 @@ switch(operation) case('bothat') se = ones(3); - BW2 = imtophat (BW, se, 'close'); + BW2 = imbothat (BW, se); if(n>1) ## TODO: check if ignoring n>1 is ok. Should I just ignore it ## TODO: without a warning? @@ -528,7 +528,7 @@ case('tophat') se = ones(3); - BW2 = imtophat (BW, se, 'open'); + BW2 = imtophat (BW, se); if(n>1) ## TODO: check if ignoring n>1 is ok. disp("WARNING: n>1 has no sense here. Using n=1. Please fill a bug if you think this behaviour is not correct"); Modified: trunk/octave-forge/main/image/inst/mmgradm.m =================================================================== --- trunk/octave-forge/main/image/inst/mmgradm.m 2011-11-02 14:57:38 UTC (rev 8928) +++ trunk/octave-forge/main/image/inst/mmgradm.m 2011-11-02 14:58:36 UTC (rev 8929) @@ -27,7 +27,7 @@ ## The morphological gradient of a image corresponds to its erosion subtracted ## to its dilation. ## -## @seealso{imerode, imdilate, imopen, imclose, imtophat} +## @seealso{imerode, imdilate, imopen, imclose, imtophat, imbothat} ## @end deftypefn function grad = mmgradm (im, se_dil, se_ero) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-11-02 19:19:13
|
Revision: 8944 http://octave.svn.sourceforge.net/octave/?rev=8944&view=rev Author: carandraug Date: 2011-11-02 19:19:06 +0000 (Wed, 02 Nov 2011) Log Message: ----------- image: properly formatted error message does not need to error trace back Modified Paths: -------------- trunk/octave-forge/main/image/inst/iptcheckconn.m trunk/octave-forge/main/image/inst/iptcheckmap.m trunk/octave-forge/main/image/inst/iptcheckstrs.m Modified: trunk/octave-forge/main/image/inst/iptcheckconn.m =================================================================== --- trunk/octave-forge/main/image/inst/iptcheckconn.m 2011-11-02 19:07:05 UTC (rev 8943) +++ trunk/octave-forge/main/image/inst/iptcheckconn.m 2011-11-02 19:19:06 UTC (rev 8944) @@ -46,25 +46,28 @@ base_msg = sprintf ("Function %s expected input number %d, %s, to be a valid connectivity specifier.\n ", ... func_name, pos, var_name); + ## error ends in \n so the back trace of the error is not show. This is on + ## purpose since the whole idea of this function is already to give a properly + ## formatted error message if (!any (strcmp (class (con), {'logical', 'double'})) || !isreal (con) || !isnumeric (con)) - error ("%sConnectivity must be a real number of the logical or double class.", base_msg); + error ("%sConnectivity must be a real number of the logical or double class.\n", base_msg); elseif (isscalar (con)) if (!any (con == [1 4 6 8 18 26])) - error ("%sIf connectivity is a scalar, must belong to the set [1 4 6 8 18 26].", base_msg); + error ("%sIf connectivity is a scalar, must belong to the set [1 4 6 8 18 26].\n", base_msg); endif elseif (ismatrix (con)) center_index = ceil(numel(con)/2); if (any (size (con) != 3)) - error ("%sIf connectivity is a matrix, all dimensions must have size 3.", base_msg); + error ("%sIf connectivity is a matrix, all dimensions must have size 3.\n", base_msg); elseif (!all (con(:) == 1 | con(:) == 0)) - error ("%sIf connectivity is a matrix, only 0 and 1 are valid.", base_msg); + error ("%sIf connectivity is a matrix, only 0 and 1 are valid.\n", base_msg); elseif (con(center_index) != 1) - error ("%sIf connectivity is a matrix, central element must be 1.", base_msg); + error ("%sIf connectivity is a matrix, central element must be 1.\n", base_msg); elseif (!all (con(1:center_index-1) == con(end:-1:center_index+1))) - error ("%sIf connectivity is a matrix, it must be symmetric relative to its center.", base_msg); + error ("%sIf connectivity is a matrix, it must be symmetric relative to its center.\n", base_msg); endif else - error ("%s", base_msg); + error ("%s\n", base_msg); endif endfunction Modified: trunk/octave-forge/main/image/inst/iptcheckmap.m =================================================================== --- trunk/octave-forge/main/image/inst/iptcheckmap.m 2011-11-02 19:07:05 UTC (rev 8943) +++ trunk/octave-forge/main/image/inst/iptcheckmap.m 2011-11-02 19:19:06 UTC (rev 8944) @@ -40,9 +40,12 @@ error ("Argument pos must be a real positive integer"); endif + ## error ends in \n so the back trace of the error is not show. This is on + ## purpose since the whole idea of this function is already to give a properly + ## formatted error message if (!strcmp (class(in), "double") || columns (in) != 3 || ndims (in) != 2 || !isreal (in) || min (in(:) < 0 || max (in(:) > 1) - error ("Function %s expected input number %d, %s, to be a valid colormap.\n ... - Valid colormaps must be nonempty, double, 2-D matrices with 3 columns.", ... + error ("Function %s expected input number %d, %s, to be a valid colormap.\n... + Valid colormaps must be nonempty, double, 2-D matrices with 3 columns.\n", ... func_name, pos, var_name); endif Modified: trunk/octave-forge/main/image/inst/iptcheckstrs.m =================================================================== --- trunk/octave-forge/main/image/inst/iptcheckstrs.m 2011-11-02 19:07:05 UTC (rev 8943) +++ trunk/octave-forge/main/image/inst/iptcheckstrs.m 2011-11-02 19:19:06 UTC (rev 8944) @@ -46,12 +46,15 @@ idx = find (strcmpi (valid_str, in) == 1, 1, "first"); + ## error ends in \n so the back trace of the error is not show. This is on + ## purpose since the whole idea of this function is already to give a properly + ## formatted error message if (isempty (idx)) valid_str = cellfun (@(x) cstrcat (x, ", "), valid_str, "UniformOutput", false); valid_str = cstrcat (valid_str{:}); error("Function %s expected its %s input argument, %s, to match one of these strings:\n... %s\n... - The input, '%s', did not match any of the valid strings.", ... + The input, '%s', did not match any of the valid strings.\n", ... func_name, iptnum2ordinal (pos), var_name, valid_str(1:end-2), in); else out = valid_str{idx}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-12-05 01:17:01
|
Revision: 9265 http://octave.svn.sourceforge.net/octave/?rev=9265&view=rev Author: carandraug Date: 2011-12-05 01:16:55 +0000 (Mon, 05 Dec 2011) Log Message: ----------- dilate and erode: added warning about being deprecated on their help text Modified Paths: -------------- trunk/octave-forge/main/image/inst/dilate.m trunk/octave-forge/main/image/inst/erode.m Modified: trunk/octave-forge/main/image/inst/dilate.m =================================================================== --- trunk/octave-forge/main/image/inst/dilate.m 2011-12-05 01:12:42 UTC (rev 9264) +++ trunk/octave-forge/main/image/inst/dilate.m 2011-12-05 01:16:55 UTC (rev 9265) @@ -19,6 +19,10 @@ ## @deftypefnx {Function File} {@var{BW2} = } dilate (@var{BW1},@var{SE},...,@var{n}) ## Perform a dilation morphological operation on a binary image. ## +## @emph{warning}: @code{dilate} has been deprecated in favor of +## @code{imdilate}. This function will be removed from future versions of the +## 'image' package". +## ## BW2 = dilate(BW1, SE) returns a binary image with the result of a dilation ## operation on @var{BW1} using neighbour mask @var{SE}. ## Modified: trunk/octave-forge/main/image/inst/erode.m =================================================================== --- trunk/octave-forge/main/image/inst/erode.m 2011-12-05 01:12:42 UTC (rev 9264) +++ trunk/octave-forge/main/image/inst/erode.m 2011-12-05 01:16:55 UTC (rev 9265) @@ -19,6 +19,10 @@ ## @deftypefnx {Function File} {@var{BW2} = } erode (@var{BW1},@var{SE},...,@var{n}) ## Perform an erosion morphological operation on a binary image. ## +## @emph{warning}: @code{erode} has been deprecated in favor of +## @code{imerode}. This function will be removed from future versions of the +## 'image' package". +## ## BW2 = erosion(BW1, SE) returns a binary image with the result of an erosion ## operation on @var{BW1} using neighbour mask @var{SE}. ## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-12-05 04:42:05
|
Revision: 9271 http://octave.svn.sourceforge.net/octave/?rev=9271&view=rev Author: carandraug Date: 2011-12-05 04:41:59 +0000 (Mon, 05 Dec 2011) Log Message: ----------- isgray isbw isrgb: return false is argument is empty matrix Modified Paths: -------------- trunk/octave-forge/main/image/inst/isbw.m trunk/octave-forge/main/image/inst/isgray.m trunk/octave-forge/main/image/inst/isrgb.m Modified: trunk/octave-forge/main/image/inst/isbw.m =================================================================== --- trunk/octave-forge/main/image/inst/isbw.m 2011-12-05 04:40:59 UTC (rev 9270) +++ trunk/octave-forge/main/image/inst/isbw.m 2011-12-05 04:41:59 UTC (rev 9271) @@ -37,7 +37,7 @@ endif ## an image cannot be a sparse matrix - if (!ismatrix (BW) || issparse (BW)) + if (!ismatrix (BW) || issparse (BW) || isempty (BW)) bool = false; elseif (strcmpi (logic, "logical")) ## this is the matlab compatible way (before they removed the function) Modified: trunk/octave-forge/main/image/inst/isgray.m =================================================================== --- trunk/octave-forge/main/image/inst/isgray.m 2011-12-05 04:40:59 UTC (rev 9270) +++ trunk/octave-forge/main/image/inst/isgray.m 2011-12-05 04:41:59 UTC (rev 9271) @@ -38,7 +38,7 @@ endif bool = false; - if (ismatrix (img) && ndims (img) == 2 && !issparse (img)) + if (ismatrix (img) && ndims (img) == 2 && !issparse (img) && !isempty (img)) switch (class (img)) case "double" ## to speed this up, we can look at a sample of the image first Modified: trunk/octave-forge/main/image/inst/isrgb.m =================================================================== --- trunk/octave-forge/main/image/inst/isrgb.m 2011-12-05 04:40:59 UTC (rev 9270) +++ trunk/octave-forge/main/image/inst/isrgb.m 2011-12-05 04:41:59 UTC (rev 9271) @@ -39,7 +39,7 @@ endif bool = false; - if (ismatrix (img) && ndims (img) == 3 && size (img, 3) == 3 && !issparse (img)) + if (ismatrix (img) && ndims (img) == 3 && size (img, 3) == 3 && !issparse (img) && !isempty (img)) switch (class (img)) case "double" ## to speed this up, we can look at a sample of the image first This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-12-09 05:11:37
|
Revision: 9318 http://octave.svn.sourceforge.net/octave/?rev=9318&view=rev Author: carandraug Date: 2011-12-09 05:11:29 +0000 (Fri, 09 Dec 2011) Log Message: ----------- blkproc: deprecating blkproc and replace by blockproc for matlab compatibility Modified Paths: -------------- trunk/octave-forge/main/image/inst/blkproc.m Added Paths: ----------- trunk/octave-forge/main/image/inst/blockproc.m Modified: trunk/octave-forge/main/image/inst/blkproc.m =================================================================== --- trunk/octave-forge/main/image/inst/blkproc.m 2011-12-09 02:20:11 UTC (rev 9317) +++ trunk/octave-forge/main/image/inst/blkproc.m 2011-12-09 05:11:29 UTC (rev 9318) @@ -15,190 +15,16 @@ ## -*- 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} +## This function has been deprecated. Please use @code{blockproc} instead which +## has exactly the same syntax. ## @end deftypefn -## Author: Josep Mones i Teixidor <jm...@pu...> - function B = blkproc(A, varargin) - if(nargin<3) - error("blkproc: invalid number of parameters."); + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "blkproc has been deprecated, and will be removed from future versions of the image package. Please use blockproc instead.") 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<p) - error("blkproc: required parameters haven't been supplied."); - endif - - if(isvector(varargin{p}) && isnumeric(varargin{p})) - if(length(varargin{p})!=2) - error("blkproc: expected [mborder,nborder] but param has wrong length."); - endif - sborder=varargin{p}(:); - p+=1; - else - sborder=[0;0]; - endif - - ## check fun - ## TODO: add proper checks for this one - if(nargin<p) - error("blkproc: required parameters haven't been supplied."); - endif - - fun=varargin{p}; - if(!isa(fun,"function_handle") && - !isa(fun,"inline function") && - !ischar(fun)) - error("blkproc: invalid fun parameter."); - endif - - ## remaining params are params to fun - ## extra params are p+1:nargin-1 - - ## First of all we calc needed padding which will be applied on bottom - ## and right borders - ## The "-" makes the function output needed elements to fill another - ## block directly - sp=mod(-size(A)',sblk); - - if(any(sp)) - A=padarray(A,sp,padval,'post'); - endif - - ## we store A size without border padding to iterate later - soa=size(A); - - ## If we have borders then we need more padding - if(any(sborder)) - A=padarray(A,sborder,padval); - endif - - ## calculate end of block - eblk=sblk+sborder*2-1; - - ## now we can process by blocks - ## we try to preserve fun return type by concatenating everything - for i=1:sblk(1):soa(1) - ## This assures r has the same class as returned by fun - r=feval(fun,A(i:i+eblk(1),1:1+eblk(2)),varargin{p+1:nargin-1}); - for j=1+sblk(2):sblk(2):soa(2) - r=horzcat(r,feval(fun,A(i:i+eblk(1),j:j+eblk(2)),varargin{p+1:nargin-1})); - endfor - if(i==1) ## this assures B has the same class as A - B=r; - else - B=vertcat(B,r); - endif - endfor + B = blockproc (A, varargin); endfunction - -%!demo -%! blkproc(eye(6),[2,2],inline("any(x(:))","x")) -%! # Returns a 3-by-3 diagonal - - -%!assert(blkproc(eye(6),[2,2],"sum"),blkproc(eye(6),[2,2],@sum)); -%!assert(blkproc(eye(6),[2,2],"sum"),blkproc(eye(6),[2,2],inline("sum(x)","x"))); -%!assert(blkproc(eye(6),[1,2],@sum),kron(eye(3),[1;1])); -%!assert(blkproc(eye(6),[2,2],inline("any(x(:))","x")),eye(3)!=0); -%!assert(blkproc(eye(6),[1,2],[1,1],inline("sum(x(:))","x")),[2,1,0;3,2,0;2,3,1;1,3,2;0,2,3;0,1,2]); -%!assert(blkproc(eye(6),'indexed',[1,2],[1,1],inline("sum(x(:))","x")),[8,5,6;6,2,3;5,3,4;4,3,5;3,2,6;6,5,8]); -%!assert(blkproc(eye(6),[2,3],[4,3],inline("sum(x(:))","x")),ones(3,2)*6); - -% Some int* and uint* tests -%!assert(blkproc(eye(6),[2,2],inline("int8(sum(x(:)))","x")),eye(3,"int8")*2); - -% Padding is 0 even for indexed -%!assert(blkproc(uint8(eye(6)),[1,2],[1,1],inline("sum(x(:))","x")),[2,1,0;3,2,0;2,3,1;1,3,2;0,2,3;0,1,2]); -%!assert(blkproc(uint8(eye(6)),'indexed',[1,2],[1,1],inline("sum(x(:))","x")),[2,1,0;3,2,0;2,3,1;1,3,2;0,2,3;0,1,2]); -%!assert(blkproc(uint16(eye(6)),[1,2],[1,1],inline("sum(x(:))","x")),[2,1,0;3,2,0;2,3,1;1,3,2;0,2,3;0,1,2]); -%!assert(blkproc(uint16(eye(6)),'indexed',[1,2],[1,1],inline("sum(x(:))","x")),[2,1,0;3,2,0;2,3,1;1,3,2;0,2,3;0,1,2]); - - -% -% $Log$ -% Revision 1.5 2007/03/23 16:14:36 adb014 -% Update the FSF address -% -% Revision 1.4 2007/01/04 23:44:22 hauberg -% Minor changes in help text -% -% Revision 1.3 2007/01/04 23:37:54 hauberg -% Minor changes in help text -% -% Revision 1.2 2006/10/08 21:41:04 adb014 -% check isnumeric for vector and 'function_handle' not 'function handle' in isa test -% -% Revision 1.1 2006/08/20 12:59:31 hauberg -% Changed the structure to match the package system -% -% Revision 1.5 2005/09/08 02:00:17 pkienzle -% [for Bill Denney] isstr -> 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 -% -% Added: trunk/octave-forge/main/image/inst/blockproc.m =================================================================== --- trunk/octave-forge/main/image/inst/blockproc.m (rev 0) +++ trunk/octave-forge/main/image/inst/blockproc.m 2011-12-09 05:11:29 UTC (rev 9318) @@ -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 <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{B} = } blockproc (@var{A}, [@var{m},@var{n}], @var{fun}) +## @deftypefnx {Function File} {@var{B} = } blockproc (@var{A}, [@var{m},@var{n}], @var{fun}, ...) +## @deftypefnx {Function File} {@var{B} = } blockproc (@var{A}, [@var{m},@var{n}], [@var{mborder},@var{nborder}], @var{fun}, @var{...}) +## @deftypefnx {Function File} {@var{B} = } blockproc (@var{A}, 'indexed', ...) +## Processes image in blocks using user-supplied function. +## +## @code{B=blockproc(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=blockproc(A,[m,n],fun,...)} behaves as described above but +## passes extra parameters to function @var{fun}. +## +## @code{B=blockproc(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=blockproc(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 <jm...@pu...> + +function B = blockproc(A, varargin) + if(nargin<3) + print_usage; + 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("blockproc: expected [m,n] but param is not a vector."); + endif + if(length(varargin{p})!=2) + error("blockproc: expected [m,n] but param has wrong length."); + endif + sblk=varargin{p}(:); + p+=1; + + ## check [mborder,nborder] + if(nargin<p) + error("blockproc: required parameters haven't been supplied."); + endif + + if(isvector(varargin{p}) && isnumeric(varargin{p})) + if(length(varargin{p})!=2) + error("blockproc: expected [mborder,nborder] but param has wrong length."); + endif + sborder=varargin{p}(:); + p+=1; + else + sborder=[0;0]; + endif + + ## check fun + ## TODO: add proper checks for this one + if(nargin<p) + error("blockproc: required parameters haven't been supplied."); + endif + + fun=varargin{p}; + if(!isa(fun,"function_handle") && + !isa(fun,"inline function") && + !ischar(fun)) + error("blockproc: invalid fun parameter."); + endif + + ## remaining params are params to fun + ## extra params are p+1:nargin-1 + + ## First of all we calc needed padding which will be applied on bottom + ## and right borders + ## The "-" makes the function output needed elements to fill another + ## block directly + sp=mod(-size(A)',sblk); + + if(any(sp)) + A=padarray(A,sp,padval,'post'); + endif + + ## we store A size without border padding to iterate later + soa=size(A); + + ## If we have borders then we need more padding + if(any(sborder)) + A=padarray(A,sborder,padval); + endif + + ## calculate end of block + eblk=sblk+sborder*2-1; + + ## now we can process by blocks + ## we try to preserve fun return type by concatenating everything + for i=1:sblk(1):soa(1) + ## This assures r has the same class as returned by fun + r=feval(fun,A(i:i+eblk(1),1:1+eblk(2)),varargin{p+1:nargin-1}); + for j=1+sblk(2):sblk(2):soa(2) + r=horzcat(r,feval(fun,A(i:i+eblk(1),j:j+eblk(2)),varargin{p+1:nargin-1})); + endfor + if(i==1) ## this assures B has the same class as A + B=r; + else + B=vertcat(B,r); + endif + endfor +endfunction + +%!demo +%! blockproc(eye(6),[2,2],inline("any(x(:))","x")) +%! # Returns a 3-by-3 diagonal + + +%!assert(blockproc(eye(6),[2,2],"sum"),blockproc(eye(6),[2,2],@sum)); +%!assert(blockproc(eye(6),[2,2],"sum"),blockproc(eye(6),[2,2],inline("sum(x)","x"))); +%!assert(blockproc(eye(6),[1,2],@sum),kron(eye(3),[1;1])); +%!assert(blockproc(eye(6),[2,2],inline("any(x(:))","x")),eye(3)!=0); +%!assert(blockproc(eye(6),[1,2],[1,1],inline("sum(x(:))","x")),[2,1,0;3,2,0;2,3,1;1,3,2;0,2,3;0,1,2]); +%!assert(blockproc(eye(6),'indexed',[1,2],[1,1],inline("sum(x(:))","x")),[8,5,6;6,2,3;5,3,4;4,3,5;3,2,6;6,5,8]); +%!assert(blockproc(eye(6),[2,3],[4,3],inline("sum(x(:))","x")),ones(3,2)*6); + +% Some int* and uint* tests +%!assert(blockproc(eye(6),[2,2],inline("int8(sum(x(:)))","x")),eye(3,"int8")*2); + +% Padding is 0 even for indexed +%!assert(blockproc(uint8(eye(6)),[1,2],[1,1],inline("sum(x(:))","x")),[2,1,0;3,2,0;2,3,1;1,3,2;0,2,3;0,1,2]); +%!assert(blockproc(uint8(eye(6)),'indexed',[1,2],[1,1],inline("sum(x(:))","x")),[2,1,0;3,2,0;2,3,1;1,3,2;0,2,3;0,1,2]); +%!assert(blockproc(uint16(eye(6)),[1,2],[1,1],inline("sum(x(:))","x")),[2,1,0;3,2,0;2,3,1;1,3,2;0,2,3;0,1,2]); +%!assert(blockproc(uint16(eye(6)),'indexed',[1,2],[1,1],inline("sum(x(:))","x")),[2,1,0;3,2,0;2,3,1;1,3,2;0,2,3;0,1,2]); + + +% +% $Log$ +% Revision 1.5 2007/03/23 16:14:36 adb014 +% Update the FSF address +% +% Revision 1.4 2007/01/04 23:44:22 hauberg +% Minor changes in help text +% +% Revision 1.3 2007/01/04 23:37:54 hauberg +% Minor changes in help text +% +% Revision 1.2 2006/10/08 21:41:04 adb014 +% check isnumeric for vector and 'function_handle' not 'function handle' in isa test +% +% Revision 1.1 2006/08/20 12:59:31 hauberg +% Changed the structure to match the package system +% +% Revision 1.5 2005/09/08 02:00:17 pkienzle +% [for Bill Denney] isstr -> 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 +% blockproc: block process an image using user-supplied function +% +% This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-12-09 19:04:01
|
Revision: 9345 http://octave.svn.sourceforge.net/octave/?rev=9345&view=rev Author: carandraug Date: 2011-12-09 19:03:54 +0000 (Fri, 09 Dec 2011) Log Message: ----------- image arithmetics: create private function that deals with input check and preparation for imadd and future imsubtract/divide/etc Modified Paths: -------------- trunk/octave-forge/main/image/inst/imadd.m Added Paths: ----------- trunk/octave-forge/main/image/inst/private/ trunk/octave-forge/main/image/inst/private/imarithmetics.m Modified: trunk/octave-forge/main/image/inst/imadd.m =================================================================== --- trunk/octave-forge/main/image/inst/imadd.m 2011-12-09 18:57:09 UTC (rev 9344) +++ trunk/octave-forge/main/image/inst/imadd.m 2011-12-09 19:03:54 UTC (rev 9345) @@ -38,26 +38,9 @@ if (nargin < 2 || nargin > 3) print_usage; - elseif ((!isnumeric (img) && !islogical (img)) || isempty (img) || issparse (img) || !isreal (img)) - error ("first argument must be a numeric or logical, non-empty, non-sparse real matrix") - elseif ((!isnumeric (val) && !islogical (val)) || isempty (val) || issparse (val) || !isreal (val)) - error ("second argument must be a numeric, non-empty, non-sparse real matrix") - elseif (!ischar (out_class)) - error ("third argument must be a string that specifies the output class") endif + [img, val] = imarithmetics ("imadd", img, val, out_class); - img_class = class (img); - if (all (size (img) == size (val)) && strcmpi (img_class, class (val))) - [img, val] = convert (out_class, img, val); - elseif (isscalar (val) && isfloat (val)) - ## according to matlab's documentation, if val is not an image of same size - ## and class as img, then it must be a double scalar. But why not also support - ## a single scalar and use isfloat? - img = convert (out_class, img); - else - error ("second argument must either be of same class and size of the first or a floating point scalar") - end - ## output class is the same as input img, unless img is logical in which case ## it should be double. Tested in matlab by Freysh at ##matlab: ## - if you imadd 2 logical matrix, it's not the union. You actually get values of 2 @@ -80,24 +63,3 @@ endif endfunction - -function [a, b] = convert (out_class, a, b = 0) - ## in the case that we only want to convert one matrix, this subfunction is called - ## with 2 arguments only. Then, b takes the value of zero so that the call to the - ## functions that change the class is insignificant - if (!strcmpi (class (a), out_class)) - switch tolower (out_class) - case {"logical"} a = logical (a); b = logical (b); - case {"uint8"} a = uint8 (a); b = uint8 (b); - case {"uint16"} a = uint16 (a); b = uint16 (b); - case {"uint32"} a = uint32 (a); b = uint32 (b); - case {"int8"} a = int8 (a); b = int8 (b); - case {"int16"} a = int16 (a); b = int16 (b); - case {"int32"} a = int32 (a); b = int32 (b); - case {"double"} a = double (a); b = double (b); - case {"single"} a = single (a); b = single (b); - otherwise - error ("requested class '%s' for output is not supported") - endswitch - endif -endfunction Added: trunk/octave-forge/main/image/inst/private/imarithmetics.m =================================================================== --- trunk/octave-forge/main/image/inst/private/imarithmetics.m (rev 0) +++ trunk/octave-forge/main/image/inst/private/imarithmetics.m 2011-12-09 19:03:54 UTC (rev 9345) @@ -0,0 +1,68 @@ +## Copyright (C) 2011 Carnë Draug <car...@gm...> +## +## 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} {} imarithmetics () +## This is a private function common to the likes of imadd, imsubtract, etc. +## +## First argument is the function name for the error message, while the others are +## the same order as the original function. It returns the two first input of the +## original function +## @end deftypefn + +function [img, val] = imarithmetics (func, img, val, out_class) + + is_valid = @(x) ((!isnumeric (x) && !islogical (x)) || isempty (x) || issparse (x) || !isreal (x)); + + if (is_valid (img)) + error ("%s: first argument must be a numeric or logical, non-empty, non-sparse real matrix", func) + elseif (is_valid (img)) + error ("%s: second argument must be a numeric, non-empty, non-sparse real matrix", func) + elseif (!ischar (out_class)) + error ("%s: third argument must be a string that specifies the output class", func) + endif + + if (all (size (img) == size (val)) && strcmpi (class (img), class (val))) + [img, val] = convert (out_class, img, val); + elseif (isscalar (val) && isfloat (val)) + ## according to matlab's documentation, if val is not an image of same size + ## and class as img, then it must be a double scalar. But why not also support + ## a single scalar and use isfloat? + img = convert (out_class, img); + else + error ("second argument must either be of same class and size of the first or a floating point scalar") + end +endfunction + +function [a, b] = convert (out_class, a, b = 0) + ## in the case that we only want to convert one matrix, this subfunction is called + ## with 2 arguments only. Then, b takes the value of zero so that the call to the + ## functions that change the class is insignificant + if (!strcmpi (class (a), out_class)) + switch tolower (out_class) + case {"logical"} a = logical (a); b = logical (b); + case {"uint8"} a = uint8 (a); b = uint8 (b); + case {"uint16"} a = uint16 (a); b = uint16 (b); + case {"uint32"} a = uint32 (a); b = uint32 (b); + case {"int8"} a = int8 (a); b = int8 (b); + case {"int16"} a = int16 (a); b = int16 (b); + case {"int32"} a = int32 (a); b = int32 (b); + case {"double"} a = double (a); b = double (b); + case {"single"} a = single (a); b = single (b); + otherwise + error ("requested class '%s' for output is not supported") + endswitch + endif +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-12-10 19:53:38
|
Revision: 9354 http://octave.svn.sourceforge.net/octave/?rev=9354&view=rev Author: carandraug Date: 2011-12-10 19:53:32 +0000 (Sat, 10 Dec 2011) Log Message: ----------- image arithmetics extensing @seealso sections Modified Paths: -------------- trunk/octave-forge/main/image/inst/imadd.m trunk/octave-forge/main/image/inst/imcomplement.m trunk/octave-forge/main/image/inst/imdivide.m trunk/octave-forge/main/image/inst/immultiply.m trunk/octave-forge/main/image/inst/imsubtract.m Modified: trunk/octave-forge/main/image/inst/imadd.m =================================================================== --- trunk/octave-forge/main/image/inst/imadd.m 2011-12-10 19:50:25 UTC (rev 9353) +++ trunk/octave-forge/main/image/inst/imadd.m 2011-12-10 19:53:32 UTC (rev 9354) @@ -32,7 +32,7 @@ ## ## @emph{Note 2}: the values are truncated to the maximum value of the output ## class. -## @seealso{imdivide, imsubtract} +## @seealso{imcomplement, imdivide, immultiply, imsubtract} ## @end deftypefn function img = imadd (img, val, out_class = class (img)) Modified: trunk/octave-forge/main/image/inst/imcomplement.m =================================================================== --- trunk/octave-forge/main/image/inst/imcomplement.m 2011-12-10 19:50:25 UTC (rev 9353) +++ trunk/octave-forge/main/image/inst/imcomplement.m 2011-12-10 19:53:32 UTC (rev 9354) @@ -21,6 +21,7 @@ ## For binary images, the complement is computed as @code{!@var{A}}, for floating ## point images it is computed as @code{1 - @var{A}}, and for integer images as ## @code{intmax(class(@var{A})) - @var{A}}. +## @seealso{imadd, imdivide, immultiply, imsubtract} ## @end deftypefn function B = imcomplement(A) Modified: trunk/octave-forge/main/image/inst/imdivide.m =================================================================== --- trunk/octave-forge/main/image/inst/imdivide.m 2011-12-10 19:50:25 UTC (rev 9353) +++ trunk/octave-forge/main/image/inst/imdivide.m 2011-12-10 19:53:32 UTC (rev 9354) @@ -28,7 +28,7 @@ ## ## @emph{Note}: the values are truncated to the mininum value of the output ## class. -## @seealso{imadd, imsubtract} +## @seealso{imadd, imcomplement, immultiply, imsubtract} ## @end deftypefn function img = imdivide (img, val, out_class = class (img)) Modified: trunk/octave-forge/main/image/inst/immultiply.m =================================================================== --- trunk/octave-forge/main/image/inst/immultiply.m 2011-12-10 19:50:25 UTC (rev 9353) +++ trunk/octave-forge/main/image/inst/immultiply.m 2011-12-10 19:53:32 UTC (rev 9354) @@ -28,7 +28,7 @@ ## ## @emph{Note}: the values are truncated to the mininum value of the output ## class. -## @seealso{imadd, imsubtract} +## @seealso{imadd, imcomplement, imdivide, imsubtract} ## @end deftypefn function img = immultiply (img, val, out_class = class (img)) Modified: trunk/octave-forge/main/image/inst/imsubtract.m =================================================================== --- trunk/octave-forge/main/image/inst/imsubtract.m 2011-12-10 19:50:25 UTC (rev 9353) +++ trunk/octave-forge/main/image/inst/imsubtract.m 2011-12-10 19:53:32 UTC (rev 9354) @@ -32,7 +32,7 @@ ## ## @emph{Note 2}: the values are truncated to the mininum value of the output ## class. -## @seealso{imadd} +## @seealso{imadd, imcomplement, imdivide, immultiply} ## @end deftypefn function img = imsubtract (img, val, out_class = class (img)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-12-10 23:06:25
|
Revision: 9359 http://octave.svn.sourceforge.net/octave/?rev=9359&view=rev Author: carandraug Date: 2011-12-10 23:06:18 +0000 (Sat, 10 Dec 2011) Log Message: ----------- image arithmetic functions: more matlab compatibility, test cases, better help text, bug fixes Modified Paths: -------------- trunk/octave-forge/main/image/inst/imadd.m trunk/octave-forge/main/image/inst/imdivide.m trunk/octave-forge/main/image/inst/immultiply.m trunk/octave-forge/main/image/inst/imsubtract.m trunk/octave-forge/main/image/inst/private/imarithmetics.m Modified: trunk/octave-forge/main/image/inst/imadd.m =================================================================== --- trunk/octave-forge/main/image/inst/imadd.m 2011-12-10 20:33:15 UTC (rev 9358) +++ trunk/octave-forge/main/image/inst/imadd.m 2011-12-10 23:06:18 UTC (rev 9359) @@ -23,7 +23,7 @@ ## to the image @var{a}. ## ## The class of @var{out} will be the same as @var{a} unless @var{a} is logical -## in which case @var{out} will be double. Alternatively, the class can be +## in which case @var{out} will be double. Alternatively, it can be ## specified with @var{class}. ## ## @emph{Note 1}: you can force output class to be logical by specifying @@ -64,3 +64,10 @@ endif endfunction + +%!assert (imadd (uint8 ([23 250]), uint8 ([23 250])), uint8 ([46 255])); # default to first class and truncate +%!assert (imadd (uint8 ([23 250]), 10), uint8 ([33 255])); # works adding a scalar +%!assert (imadd (uint8 ([23 250]), uint8 ([23 250]), "uint16"), uint16 ([46 500])); # defining output class works +%!assert (imadd (logical ([ 1 0]), logical ([ 1 1])), double ([ 2 1])); # return double for two logical images +%!assert (imadd (logical ([ 1 0]), logical ([ 1 1]), "logical"), logical ([ 1 1])); # this is matlab incompatible on purpose +%!fail ("imadd (uint8 ([23 250]), uint16 ([23 250]))") # input need to have same class Modified: trunk/octave-forge/main/image/inst/imdivide.m =================================================================== --- trunk/octave-forge/main/image/inst/imdivide.m 2011-12-10 20:33:15 UTC (rev 9358) +++ trunk/octave-forge/main/image/inst/imdivide.m 2011-12-10 23:06:18 UTC (rev 9359) @@ -23,7 +23,7 @@ ## by it. ## ## The class of @var{out} will be the same as @var{a} unless @var{a} is logical -## in which case @var{out} will be double. Alternatively, the class can be +## in which case @var{out} will be double. Alternatively, it can be ## specified with @var{class}. ## ## @emph{Note}: the values are truncated to the mininum value of the output @@ -52,3 +52,10 @@ end_unwind_protect endfunction + +%!assert (imdivide (uint8 ([23 250]), uint8 ([ 2 50])), uint8 ([ 12 5])); # default to first class +%!assert (imdivide (uint8 ([56 255]), uint8 ([ 0 0])), uint8 ([255 255])); # dividing by zero works (tested in matlab) +%!assert (imdivide (uint8 ([23 250]), 2), uint8 ([ 12 125])); # works subtracting a scalar +%!assert (imdivide (uint8 ([23 250]), uint8 ([ 2 50]), "uint16"), uint16 ([ 12 5])); # defining output class works (not in matlab) +%!assert (imdivide (logical ([1 1 0 0]), logical ([1 0 1 0])), double ([1 Inf 0 NaN])); # dividing logical matrix (tested in matlab) +%!fail ("imdivide (uint8 ([23 250]), uint16 ([23 250]))") # input needs to have same class Modified: trunk/octave-forge/main/image/inst/immultiply.m =================================================================== --- trunk/octave-forge/main/image/inst/immultiply.m 2011-12-10 20:33:15 UTC (rev 9358) +++ trunk/octave-forge/main/image/inst/immultiply.m 2011-12-10 23:06:18 UTC (rev 9359) @@ -23,7 +23,7 @@ ## multiplie by it. ## ## The class of @var{out} will be the same as @var{a} unless @var{a} is logical -## in which case @var{out} will be double. Alternatively, the class can be +## in which case @var{out} will be double. Alternatively, it can be ## specified with @var{class}. ## ## @emph{Note}: the values are truncated to the mininum value of the output @@ -36,10 +36,11 @@ if (nargin < 2 || nargin > 3) print_usage; endif - [img, val] = imarithmetics ("immultiply", img, val, out_class); + [img, val] = imarithmetics ("immultiply", img, val, out_class, nargin); - ## matlab doesn't even gives a warning in this situation, it simply returns - ## a double precision float + ## have to check how matlab behaves in this situtation. Their documentation + ## does not say anything but add and subtract silently ignore it and return + ## double anyway. This may be done in the call to imarithmetics if (nargin > 2 && strcmpi (out_class, "logical")) warning ("Ignoring request to return logical as output of multiplication."); endif @@ -47,3 +48,9 @@ img = img .* val; endfunction + +%!assert (immultiply (uint8 ([255 50]), uint16 ([300 50])), uint8 ([255 255])); # default to first class and truncate +%!assert (immultiply (uint8 ([250 50]), uint16 ([ 3 4]), "uint32"), uint32 ([750 400])); # defining output class works (not in matlab?) +%!assert (immultiply (uint8 ([255 50]), 4), uint8 ([255 200])); # works multiplying by a scalar +%!assert (immultiply (logical ([ 1 0]), uint16 ([300 50])), uint16 ([300 0])); # output class defaults to whatever input is not logical +%!assert (immultiply (logical ([ 1 0]), logical ([ 1 1])), double ([ 1 0])); # tested on matlab for compatibility Modified: trunk/octave-forge/main/image/inst/imsubtract.m =================================================================== --- trunk/octave-forge/main/image/inst/imsubtract.m 2011-12-10 20:33:15 UTC (rev 9358) +++ trunk/octave-forge/main/image/inst/imsubtract.m 2011-12-10 23:06:18 UTC (rev 9359) @@ -23,7 +23,7 @@ ## to the image @var{a}. ## ## The class of @var{out} will be the same as @var{a} unless @var{a} is logical -## in which case @var{out} will be double. Alternatively, the class can be +## in which case @var{out} will be double. Alternatively, it can be ## specified with @var{class}. ## ## @emph{Note 1}: you can force output class to be logical by specifying @@ -32,6 +32,20 @@ ## ## @emph{Note 2}: the values are truncated to the mininum value of the output ## class. +## +## @emph{NOte 3}: values are truncated before the operation so if input images are +## unsigned integers and the request output class is a signed integer, it may lead +## to unexpected results: +## +## @example +## @group +## imsubtract (uint8 ([23 190]), uint8 ([24 200]), "int8") +## @result{} -1 0 +## @end group +## @end example +## +## Because both 190 and 200 were truncated to 127 before subtraction, their difference +## is zero. ## @seealso{imadd, imcomplement, imdivide, immultiply} ## @end deftypefn @@ -39,7 +53,15 @@ if (nargin < 2 || nargin > 3) print_usage; + elseif (any (isa (img, {"uint8", "uint16", "uint32", "uint64"})) && any (strcmpi (out_class, {"int8", "int16", "int32", "int64"}))) + ## because we convert the images before the subtraction, if input is: + ## imsubtract (uint8(150), uint8 (200), "int8"); + ## rsult will be 0 because both values are truncated to 127 before subtraction. + ## There is no matlab compatibility issue because matlab does not have the option + ## to specify output class in imsubtract + warning ("input images are unsigned integers but requested output is signed integer. This may lead to unexpected results."); endif + [img, val] = imarithmetics ("imsubtract", img, val, out_class); ## The following makes the code imcompatible with matlab on certain cases. @@ -51,3 +73,11 @@ endif endfunction + +%!assert (imsubtract (uint8 ([23 250]), uint8 ([24 50])), uint8 ([ 0 200])); # default to first class and truncate +%!assert (imsubtract (uint8 ([23 250]), 10), uint8 ([13 240])); # works subtracting a scalar +%!assert (imsubtract (uint8 ([23 250]), uint8 ([24 50]), "uint16"), uint16 ([ 0 200])); # defining output class works (not in matlab) +%!assert (imsubtract (uint8 ([23 250]), uint8 ([24 255]), "int8"), int8 ([-1 0])); # signed integers kinda work (not in matlab) +%!assert (imsubtract (logical ([ 1 0]), logical ([ 1 1])), double ([ 0 -1])); # return double for two logical images +%!assert (imsubtract (logical ([ 1 0]), logical ([ 1 1]), "logical"), logical ([ 0 0])); # this is matlab incompatible on purpose +%!fail ("imsubtract (uint8 ([23 250]), uint16 ([23 250]))") # input need to have same class Modified: trunk/octave-forge/main/image/inst/private/imarithmetics.m =================================================================== --- trunk/octave-forge/main/image/inst/private/imarithmetics.m 2011-12-10 20:33:15 UTC (rev 9358) +++ trunk/octave-forge/main/image/inst/private/imarithmetics.m 2011-12-10 23:06:18 UTC (rev 9359) @@ -22,7 +22,7 @@ ## original function ## @end deftypefn -function [img, val] = imarithmetics (func, img, val, out_class) +function [img, val] = imarithmetics (func, img, val, out_class, in_args) is_valid = @(x) ((!isnumeric (x) && !islogical (x)) || isempty (x) || issparse (x) || !isreal (x)); @@ -34,9 +34,20 @@ error ("%s: third argument must be a string that specifies the output class", func) endif - if (all (size (img) == size (val)) && strcmpi (class (img), class (val))) + same_size = all (size (img) == size (val)); + if (same_size && strcmpi (class (img), class (val))) [img, val] = convert (out_class, img, val); - elseif (isscalar (val) && isfloat (val)) + + ## multiplication doesn't require same input class and output class defaults to + ## whatever input class is not logical (first img, then val) + elseif (strcmp (func, "immultiply") && same_size) + if (in_args > 2) + ## user defined, do nothing + elseif (islogical (img) && !islogical (val)) + out_class = class (val); + endif + [img, val] = convert (out_class, img, val); + elseif (isscalar (val) && isfloat (val) && !strcmp (func, "imabsdiff")) ## according to matlab's documentation, if val is not an image of same size ## and class as img, then it must be a double scalar. But why not also support ## a single scalar and use isfloat? @@ -50,7 +61,7 @@ ## in the case that we only want to convert one matrix, this subfunction is called ## with 2 arguments only. Then, b takes the value of zero so that the call to the ## functions that change the class is insignificant - if (!strcmpi (class (a), out_class)) + if ((nargin == 3 && any (!strcmpi ({class(a), class(b)}, out_class))) || (nargin == 2 && !strcmpi (class (a), out_class))) switch tolower (out_class) case {"logical"} a = logical (a); b = logical (b); case {"uint8"} a = uint8 (a); b = uint8 (b); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-04-11 17:01:46
|
Revision: 10193 http://octave.svn.sourceforge.net/octave/?rev=10193&view=rev Author: carandraug Date: 2012-04-11 17:01:36 +0000 (Wed, 11 Apr 2012) Log Message: ----------- im2double: added new private function that will be used for input checking of all im2_class functions Modified Paths: -------------- trunk/octave-forge/main/image/inst/im2double.m Added Paths: ----------- trunk/octave-forge/main/image/inst/private/imconversion.m Modified: trunk/octave-forge/main/image/inst/im2double.m =================================================================== --- trunk/octave-forge/main/image/inst/im2double.m 2012-04-11 16:45:41 UTC (rev 10192) +++ trunk/octave-forge/main/image/inst/im2double.m 2012-04-11 17:01:36 UTC (rev 10193) @@ -36,35 +36,26 @@ ## @seealso{im2bw, im2uint16, im2uint8} ## @end deftypefn -function im2 = im2double (im1, ind = false) - ## Input checking - if (nargin < 1 || nargin > 2) - print_usage; - elseif (nargin == 2 && (!ischar (ind) || !strcmpi (ind, "indexed"))) - error ("second argument must be a string with the word `indexed'"); - endif +function im = im2double (im, ind = false) - if (ind && !isind (im1)) - error ("input should have been an indexed image but it is not"); - endif + ## Input checking (private function that is used for all im2class functions) + im_class = imconversion (nargin, "im2double", ind, im); - ## Take action depending on the class of the data - in_class = class (im1); - switch in_class + switch im_class case "double" - im2 = im1; + ## do nothing, return the same case {"logical", "single"} - im2 = double (im1); + im = double (im); case {"uint8", "uint16"} if (ind) - im2 = double (im1) + 1; - elseif (isind (im1)) - im2 = double (im1) / double (intmax (in_class)); + im = double (im) + 1; + elseif (isind (im)) + im = double (im) / double (intmax (im_class)); endif case "int16" - im2 = (double (im1) + double (intmax (in_class)) + 1) / double (intmax ("uint16")); + im = (double (im) + double (intmax (im_class)) + 1) / double (intmax ("uint16")); otherwise - error ("unsupported image class"); + error ("unsupported image class %s", im_class); endswitch endfunction Added: trunk/octave-forge/main/image/inst/private/imconversion.m =================================================================== --- trunk/octave-forge/main/image/inst/private/imconversion.m (rev 0) +++ trunk/octave-forge/main/image/inst/private/imconversion.m 2012-04-11 17:01:36 UTC (rev 10193) @@ -0,0 +1,34 @@ +## Copyright (C) 2012 Carnë Draug <car...@gm...> +## +## 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/>. + +## This is a private fucntion for the common code between the functions that +## convert an input image into another class. Mostly does the input checking for +## all of them and returns the class of the input image + +function im_class = imconversion (nargs, fname, ind, im1) + ## Input checking + if (nargs < 1 || nargs > 2) + print_usage (fname); + elseif (nargs == 2 && (!ischar (ind) || !strcmpi (ind, "indexed"))) + error ("%s: second argument must be a string with the word `indexed'\n", fname); + endif + + if (ind && !isind (im1)) + error ("%s: input should have been an indexed image but it is not.\n", fname); + endif + + im_class = class (im1); + +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-09-02 02:31:59
|
Revision: 10941 http://octave.svn.sourceforge.net/octave/?rev=10941&view=rev Author: carandraug Date: 2012-09-02 02:31:53 +0000 (Sun, 02 Sep 2012) Log Message: ----------- isbw: delegate checks to new shared private functions and add test blocks Modified Paths: -------------- trunk/octave-forge/main/image/inst/isbw.m Added Paths: ----------- trunk/octave-forge/main/image/inst/private/isimage.m trunk/octave-forge/main/image/inst/private/ispart.m Modified: trunk/octave-forge/main/image/inst/isbw.m =================================================================== --- trunk/octave-forge/main/image/inst/isbw.m 2012-09-02 01:53:19 UTC (rev 10940) +++ trunk/octave-forge/main/image/inst/isbw.m 2012-09-02 02:31:53 UTC (rev 10941) @@ -17,12 +17,12 @@ ## -*- texinfo -*- ## @deftypefn {Function File} @var{bool} = isbw (@var{img}) ## @deftypefnx {Function File} @var{bool} = isbw (@var{img}, @var{logic}) -## Return true if @var{img} is a black-white image. +## Return true if @var{img} is a black and white image. ## -## The optional argument @var{logic} must be the string `logical' or -## `non-logical'. The first defines a black and white image as a logical matrix, -## while the second defines it as a matrix comprised of the values 1 and 0 -## only. Defaults to `logical'. +## The optional argument @var{logic} defines what is considered a black and +## white image. Possible values are the strings `logical' or `non-logical'. The +## first defines it as a logical matrix, while the second defines it as a matrix +## where the only values are 1 and 0. Defaults to `logical'. ## ## @seealso{isgray, isind, islogical, isrgb} ## @end deftypefn @@ -36,32 +36,27 @@ error ("second argument must either be a string 'logical' or 'non-logical'") endif - ## an image cannot be a sparse matrix - if (!ismatrix (BW) || issparse (BW) || isempty (BW)) + bool = false; + if (!isimage (BW)) bool = false; elseif (strcmpi (logic, "logical")) ## this is the matlab compatible way (before they removed the function) bool = islogical (BW); - ## the following block is just temporary to keep backwards compatibility - if (!islogical (BW) && is_bw_nonlogical (BW)) + ## FIXME the following block is just temporary to keep backwards compatibility + if (nargin == 1 && !islogical (BW) && isbw (BW, "non-logical")) persistent warned = false; if (! warned) warned = true; warning ("isbw: image is not logical matrix and therefore not binary but all values are either 0 and 1.") - warning ("isbw: future versions of this function will return true. Consider using the call isbw (img, \"non-logical\").") + warning ("isbw: future versions of this function will return true. Consider using the call `isbw (img, \"non-logical\")'.") endif bool = true; endif ## end of temporary block for backwards compatibility elseif (strcmpi (logic, "non-logical")) - ## to speed this up, we can look at a sample of the image first - bool = is_bw_nonlogical (BW(1:ceil (rows (BW) /100), 1:ceil (columns (BW) /100))); - if (bool) - ## sample was true, we better make sure it's real - bool = is_bw_nonlogical (BW); - endif + bool = ispart (@is_bw_nonlogical, BW); endif endfunction @@ -69,3 +64,12 @@ function bool = is_bw_nonlogical (BW) bool = all (all ((BW == 1) + (BW == 0))); endfunction + +%!shared a +%! a = round(rand(100)); +%!assert (isbw (a, "non-logical"), true); +%!assert (isbw (a, "logical"), false); +%!assert (isbw (logical(a), "logical"), true); +%!assert (isbw (logical(a), "non-logical"), true); +%! a(50, 50) = 2; +%!assert (isbw (a, "non-logical"), false); Added: trunk/octave-forge/main/image/inst/private/isimage.m =================================================================== --- trunk/octave-forge/main/image/inst/private/isimage.m (rev 0) +++ trunk/octave-forge/main/image/inst/private/isimage.m 2012-09-02 02:31:53 UTC (rev 10941) @@ -0,0 +1,24 @@ +## Copyright (C) 2012 Carnë Draug <car...@gm...> +## +## 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/>. + +## This a private function for the is... type of functions for the image package +## It simply checks if the input really is an image. + +function bool = isimage (img) + bool = true; + if (!ismatrix (img) || issparse (img) || isempty (img)) + bool = false; + endif +endfunction Added: trunk/octave-forge/main/image/inst/private/ispart.m =================================================================== --- trunk/octave-forge/main/image/inst/private/ispart.m (rev 0) +++ trunk/octave-forge/main/image/inst/private/ispart.m 2012-09-02 02:31:53 UTC (rev 10941) @@ -0,0 +1,25 @@ +## Copyright (C) 2012 Carnë Draug <car...@gm...> +## +## 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/>. + +## This a private function for the is... type of functions for the image package +## Rather than checking the whol image, there can be a speed up by checking only +## a corner of the image first and then the rest if that part is true. + +function bool = ispart (foo, in) + bool = foo (in(1:ceil (rows (in) /100), 1:ceil (columns (in) /100))); + if (bool) + bool = foo (in); + endif +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-09-02 02:37:18
|
Revision: 10943 http://octave.svn.sourceforge.net/octave/?rev=10943&view=rev Author: carandraug Date: 2012-09-02 02:37:12 +0000 (Sun, 02 Sep 2012) Log Message: ----------- isgray: use shared private functions for checks and added test blocks Modified Paths: -------------- trunk/octave-forge/main/image/inst/isbw.m trunk/octave-forge/main/image/inst/isgray.m Modified: trunk/octave-forge/main/image/inst/isbw.m =================================================================== --- trunk/octave-forge/main/image/inst/isbw.m 2012-09-02 02:33:14 UTC (rev 10942) +++ trunk/octave-forge/main/image/inst/isbw.m 2012-09-02 02:37:12 UTC (rev 10943) @@ -62,7 +62,7 @@ endfunction function bool = is_bw_nonlogical (BW) - bool = all ((BW == 1)(:) + (BW == 0)(:)); + bool = all ((BW(:) == 1) + (BW(:) == 0)); endfunction %!shared a Modified: trunk/octave-forge/main/image/inst/isgray.m =================================================================== --- trunk/octave-forge/main/image/inst/isgray.m 2012-09-02 02:33:14 UTC (rev 10942) +++ trunk/octave-forge/main/image/inst/isgray.m 2012-09-02 02:37:12 UTC (rev 10943) @@ -38,15 +38,12 @@ endif bool = false; - if (ismatrix (img) && ndims (img) == 2 && !issparse (img) && !isempty (img)) + if (!isimage (img)) + bool = false; + elseif (ndims (img) == 2) switch (class (img)) case "double" - ## to speed this up, we can look at a sample of the image first - bool = is_gray_double (img(1:ceil (rows (img) /100), 1:ceil (columns (img) /100))); - if (bool) - ## sample was true, we better make sure it's real - bool = is_gray_double (img); - endif + bool = ispart (@is_gray_double, img); case {"uint8", "uint16"} bool = true; endswitch @@ -57,3 +54,13 @@ function bool = is_gray_double (img) bool = all ((img(:) >= 0 & img(:) <= 1) | isnan (img(:))); endfunction + +%!shared a +%! a = rand (100); +%!assert (isgray (a), true); +%! a(50, 50) = 2; +%!assert (isgray (a), false); +%! a = uint8 (randi (255, 100)); +%!assert (isgray (a), true); +%! a = int8 (a); +%!assert (isgray (a), false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-09-02 03:17:53
|
Revision: 10946 http://octave.svn.sourceforge.net/octave/?rev=10946&view=rev Author: carandraug Date: 2012-09-02 03:17:47 +0000 (Sun, 02 Sep 2012) Log Message: ----------- isimage: also check if input is real Modified Paths: -------------- trunk/octave-forge/main/image/inst/isind.m trunk/octave-forge/main/image/inst/private/isimage.m Modified: trunk/octave-forge/main/image/inst/isind.m =================================================================== --- trunk/octave-forge/main/image/inst/isind.m 2012-09-02 02:48:30 UTC (rev 10945) +++ trunk/octave-forge/main/image/inst/isind.m 2012-09-02 03:17:47 UTC (rev 10946) @@ -39,7 +39,7 @@ bool = false; if (!isimage (img)) bool = false; - elseif (ndims (img) == 2 && isreal (img)) + elseif (ndims (img) == 2) switch (class (img)) case "double" bool = isindex (img); Modified: trunk/octave-forge/main/image/inst/private/isimage.m =================================================================== --- trunk/octave-forge/main/image/inst/private/isimage.m 2012-09-02 02:48:30 UTC (rev 10945) +++ trunk/octave-forge/main/image/inst/private/isimage.m 2012-09-02 03:17:47 UTC (rev 10946) @@ -18,7 +18,7 @@ function bool = isimage (img) bool = true; - if (!ismatrix (img) || issparse (img) || isempty (img)) + if (!ismatrix (img) || issparse (img) || isempty (img) || !isreal (img)) bool = false; endif endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-09-02 03:41:46
|
Revision: 10949 http://octave.svn.sourceforge.net/octave/?rev=10949&view=rev Author: carandraug Date: 2012-09-02 03:41:40 +0000 (Sun, 02 Sep 2012) Log Message: ----------- is_double_image: new private function to check if an image of class double is valid Modified Paths: -------------- trunk/octave-forge/main/image/inst/isgray.m trunk/octave-forge/main/image/inst/isrgb.m Added Paths: ----------- trunk/octave-forge/main/image/inst/private/is_double_image.m Modified: trunk/octave-forge/main/image/inst/isgray.m =================================================================== --- trunk/octave-forge/main/image/inst/isgray.m 2012-09-02 03:33:55 UTC (rev 10948) +++ trunk/octave-forge/main/image/inst/isgray.m 2012-09-02 03:41:40 UTC (rev 10949) @@ -43,7 +43,7 @@ elseif (ndims (img) == 2) switch (class (img)) case "double" - bool = ispart (@is_gray_double, img); + bool = ispart (@is_double_image, img); case {"uint8", "uint16"} bool = true; endswitch @@ -51,10 +51,6 @@ endfunction -function bool = is_gray_double (img) - bool = all ((img(:) >= 0 & img(:) <= 1) | isnan (img(:))); -endfunction - %!shared a %! a = rand (100); %!assert (isgray (a), true); Modified: trunk/octave-forge/main/image/inst/isrgb.m =================================================================== --- trunk/octave-forge/main/image/inst/isrgb.m 2012-09-02 03:33:55 UTC (rev 10948) +++ trunk/octave-forge/main/image/inst/isrgb.m 2012-09-02 03:41:40 UTC (rev 10949) @@ -44,7 +44,7 @@ elseif (ndims (img) == 3 && size (img, 3) == 3) switch (class (img)) case "double" - bool = ispart (@is_rgb_double, img); + bool = ispart (@is_double_image, img); case {"uint8", "uint16"} bool = true; endswitch @@ -52,10 +52,6 @@ endfunction -function bool = is_rgb_double (img) - bool = all ((img(:) >= 0 & img(:) <= 1) | isnan (img(:))); -endfunction - %!# Non-matrix %!assert(isrgb("this is not a RGB image"),false); Added: trunk/octave-forge/main/image/inst/private/is_double_image.m =================================================================== --- trunk/octave-forge/main/image/inst/private/is_double_image.m (rev 0) +++ trunk/octave-forge/main/image/inst/private/is_double_image.m 2012-09-02 03:41:40 UTC (rev 10949) @@ -0,0 +1,21 @@ +## Copyright (C) 2012 Carnë Draug <car...@gm...> +## +## 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/>. + +## simple check used by some functions. Images of the double class must have +## all their values between 0 and 1 or be NaN + +function bool = is_double_image (img) + bool = all ((img(:) >= 0 & img(:) <= 1) | isnan (img(:))); +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-09-02 03:52:23
|
Revision: 10950 http://octave.svn.sourceforge.net/octave/?rev=10950&view=rev Author: carandraug Date: 2012-09-02 03:52:17 +0000 (Sun, 02 Sep 2012) Log Message: ----------- iscolormap: also check class and number of dimensions Modified Paths: -------------- trunk/octave-forge/main/image/inst/iptcheckmap.m trunk/octave-forge/main/image/inst/iscolormap.m Modified: trunk/octave-forge/main/image/inst/iptcheckmap.m =================================================================== --- trunk/octave-forge/main/image/inst/iptcheckmap.m 2012-09-02 03:41:40 UTC (rev 10949) +++ trunk/octave-forge/main/image/inst/iptcheckmap.m 2012-09-02 03:52:17 UTC (rev 10950) @@ -43,7 +43,7 @@ ## error ends in \n so the back trace of the error is not show. This is on ## purpose since the whole idea of this function is already to give a properly ## formatted error message - if (!strcmp (class(in), "double") || columns (in) != 3 || ndims (in) != 2 || !isreal (in) || min (in(:) < 0) || max (in(:) > 1)) + if (!iscolormap (in)) error ("Function %s expected input number %d, %s, to be a valid colormap.\n... Valid colormaps must be nonempty, double, 2-D matrices with 3 columns.\n", ... func_name, pos, var_name); Modified: trunk/octave-forge/main/image/inst/iscolormap.m =================================================================== --- trunk/octave-forge/main/image/inst/iscolormap.m 2012-09-02 03:41:40 UTC (rev 10949) +++ trunk/octave-forge/main/image/inst/iscolormap.m 2012-09-02 03:52:17 UTC (rev 10950) @@ -31,7 +31,8 @@ endif bool = false; - if (ismatrix (cm) && isnumeric (cm) && columns(cm) == 3 && + if (ismatrix (cm) && isreal (cm) isnumeric (cm) && columns(cm) == 3 && + ndims (cm) == 2 && strcmp (class (cm), "double") && min (cm(:)) >= 0 && max (cm(:)) <= 1) bool = true; endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-09-21 12:44:18
|
Revision: 11063 http://octave.svn.sourceforge.net/octave/?rev=11063&view=rev Author: carandraug Date: 2012-09-21 12:44:08 +0000 (Fri, 21 Sep 2012) Log Message: ----------- im2float: common code from im2single and im2double in private function Modified Paths: -------------- trunk/octave-forge/main/image/inst/im2double.m trunk/octave-forge/main/image/inst/im2single.m Added Paths: ----------- trunk/octave-forge/main/image/inst/private/im2float.m Modified: trunk/octave-forge/main/image/inst/im2double.m =================================================================== --- trunk/octave-forge/main/image/inst/im2double.m 2012-09-21 12:23:35 UTC (rev 11062) +++ trunk/octave-forge/main/image/inst/im2double.m 2012-09-21 12:44:08 UTC (rev 11063) @@ -37,30 +37,7 @@ ## @end deftypefn function im = im2double (im, indexed = false) - - ## Input checking (private function that is used for all im2class functions) - im_class = imconversion (nargin, "im2double", indexed, im); - - ## READ BEFORE MAKE CHANGES: - ## this function is pretty much the same as im2single. Any changes on this code - ## should most likely also be done there - - switch im_class - case "double" - ## do nothing, return the same - case {"logical", "single"} - im = double (im); - case {"uint8", "uint16"} - if (indexed) - im = double (im) + 1; - else - im = double (im) / double (intmax (im_class)); - endif - case "int16" - im = (double (im) + double (intmax (im_class)) + 1) / double (intmax ("uint16")); - otherwise - error ("unsupported image class %s", im_class); - endswitch + im = im2float ("double", nargin, im, indexed); endfunction %!assert(im2double([1 2 3]), [1 2 3]); # double returns the same Modified: trunk/octave-forge/main/image/inst/im2single.m =================================================================== --- trunk/octave-forge/main/image/inst/im2single.m 2012-09-21 12:23:35 UTC (rev 11062) +++ trunk/octave-forge/main/image/inst/im2single.m 2012-09-21 12:44:08 UTC (rev 11063) @@ -36,30 +36,7 @@ ## @end deftypefn function im = im2single (im, indexed = false) - - ## Input checking (private function that is used for all im2class functions) - im_class = imconversion (nargin, "im2single", indexed, im); - - ## READ BEFORE MAKE CHANGES: - ## this function is pretty much the same as im2double. Any changes on this code - ## should most likely also be done there - - switch im_class - case "single" - ## do nothing, return the same - case {"logical", "double"} - im = single (im); - case {"uint8", "uint16"} - if (indexed) - im = single (im) + 1; - else - im = single (im) / single (intmax (im_class)); - endif - case "int16" - im = (single (im) + single (intmax (im_class)) + 1) / single (intmax ("uint16")); - otherwise - error ("unsupported image class %s", im_class); - endswitch + im = im2float ("single", nargin, im, indexed); endfunction %!assert(im2single([1 2 3]), single([1 2 3])); # double returns the same Added: trunk/octave-forge/main/image/inst/private/im2float.m =================================================================== --- trunk/octave-forge/main/image/inst/private/im2float.m (rev 0) +++ trunk/octave-forge/main/image/inst/private/im2float.m 2012-09-21 12:44:08 UTC (rev 11063) @@ -0,0 +1,43 @@ +## Copyright (C) 2012 Carnë Draug <car...@gm...> +## +## 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/>. + +## im2double and im2single are very similar so here's the common code, +## which is prety much all of it. + +function im = im2float (out_class, caller_nargin, im, indexed = false) + + ## Input checking (private function that is used for all im2class functions) + im_class = imconversion (caller_nargin, ["im2" out_class], indexed, im); + + converter = eval (["@" out_class]); + switch im_class + case {"single", "double", "logical"} + if (strcmp (im_class, out_class)) + ## do nothing, return the same + else + im = converter (im); + endif + case {"uint8", "uint16"} + if (indexed) + im = converter (im) + 1; + else + im = converter (im) / converter (intmax (im_class)); + endif + case "int16" + im = (converter (im) + converter (intmax (im_class)) + 1) / converter (intmax ("uint16")); + otherwise + error ("unsupported image class %s", im_class); + endswitch +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |