Mercurial > hg > octave-image
changeset 483:7e92182aba4d
imbothat: new function for image package and modified imtophat to use it
author | carandraug |
---|---|
date | Wed, 02 Nov 2011 14:41:30 +0000 |
parents | dc7ab6803293 |
children | 27c9e8ad9d44 |
files | inst/imbothat.m inst/imtophat.m |
diffstat | 2 files changed, 59 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/inst/imbothat.m @@ -0,0 +1,52 @@ +## Copyright (C) 2005 Carvalho-Mariel +## Copyright (C) 2010-2011 Carnë Draug <carandraug+dev@gmail.com> +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2 +## of the License, or (at your option) any later version. +## +## This program is 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
--- a/inst/imtophat.m +++ b/inst/imtophat.m @@ -1,5 +1,5 @@ ## Copyright (C) 2005 Carvalho-Mariel -## Copyright (C) 2010 Carnë Draug <carandraug+dev@gmail.com> +## Copyright (C) 2010-2011 Carnë Draug <carandraug+dev@gmail.com> ## ## 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); - -