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. |