On 22 November 2011 20:53, Adrián del Pino <delpinonavarr...@gmail.com> wrote:
> On Mon, Nov 21, 2011 at 9:59 PM, Carnë Draug <carandraug+...@gmail.com>
> wrote:
>>
>> On 26 October 2011 16:19, Adrián del Pino <delpinonavarr...@gmail.com>
>> wrote:
>> > Dear Octave:
>> > Sometimes the function bweuler returns incorrect values. By example,
>> > it
>> > returns -0.5 instead of 1 with this image ("prueba3.tif"). Moreover,
>> > this
>> > function should return integer values.
>> >
>> > Best regards.
>> > Adrián del Pino
>>
>> Hi Adrián
>>
>> just to let you know that this was not forgotten. I was hoping that
>> someone would show up and manage to fix it. As that doesn't seem to be
>> happening, I added your report to the bug tracker here
>>
>> https://sourceforge.net/tracker/?func=detail&aid=3440926&group_id=2888&atid=102888
>>
>> It would be great if you were able to fix the problem and submit a
>> patch for it. The function is written in the GNU octave language so it
>> shouldn't be too hard provided you know the subject. The link for the
>> latest revision of the file is
>>
>> http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/main/image/inst/bweuler.m
>>
>> I have also CC'ed the dev that wrote this function.
>>
>> Carnë
>
> Hi Carnë,
> I have fixed two problems in this function. There was no validation of
> the input image and there was a problem computing values when a figure
> touches the top and left borders.
>
> I want to submit the new version but the procedure seems a little
> complex.
You are right. I should spend an hour sometime this week and write
more up to date and simpler instructions. It's actually quite simple.
> Also, I don't know if I should write the log at the end of the file.
No, you should not. You did right.
> I have attached the file to receive your comments.
I made a few more changes but mostly aesthetical. I defined the
defaults of n at the top with "function eul = bweuler (BW, n = 8)" and
used print_usage for wrong inputs. I made sure that n was a numeric
scalar before checking its value otheriwse some weird error would
appear if the user tried to use a string.
I also changed a bit the help text, and added you to copyright notice.
Is this the e-mail you want on the copyright notice? See the attached
file.
Also, the help text mentions that it uses the Bit Quads as described
in "Digital Image Processing". I don't know if this is still true
after your changes.
If no one objects against the attached file in 3 days, I'll commit it.
Carnë
## Copyright (C) 2004 Josep Mones i Teixidor <jmo...@puntbarra.com>
## Copyright (C) 2011 Adrián del Pino <delpinonavarr...@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 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} {@var{eul} = } bweuler (@var{BW}, @var{n})
## Calculate the Euler number of a binary image.
##
## This function calculates the Euler number @var{eul} of a binary
## image @var{BW}. This number is a scalar whose value represents the total
## number of objects in @var{BW} minus the number of holes.
##
## @var{n} is an optional argument that specifies the neighbourhood
## connectivity. Must either be 4 or 8. If omitted, defaults to 8.
##
## This function uses Bit Quads as described in "Digital Image
## Processing" to calculate euler number.
##
## References:
## W. K. Pratt, "Digital Image Processing", 3rd Edition, pp 593-595
##
## @seealso{bwmorph, bwperim, qtgetblk}
## @end deftypefn
## Author: Josep Mones i Teixidor <jmo...@puntbarra.com>
function eul = bweuler (BW, n = 8)
if (nargin < 1 || nargin > 2)
print_usage;
endif
if (!isbw (BW))
error("first argument must be a Black and White image");
endif
## we precalculate this...
if (!isnumeric (n) || !isscalar (n) || (n != 8 && n != 4))
error("second argument must either be 4 or 8");
elseif (n == 8)
lut = [0; 0.25; 0.25; 0; 0.25; 0; -0.5; -0.25; 0.25; -0.5; 0; -0.25; 0; -0.25; -0.25; 0];
elseif (n == 4)
lut = [0; 0.25; 0.25; 0; 0.25; 0; 0.5; -0.25; 0.25; 0.5; 0; -0.25; 0; -0.25; -0.25; 0];
endif
## adding zeros to the top and left bordes to avoid errors when figures touch these borders.
## For example, 1 0 gives 0.25 because there are three one-pixel and one diagonal pixels.
## 0 1
## So, we have 3*0.25 - 0.5 = 0.25 (error) instead of 1 (correct).
## Fortunately, there is no need to add zeros to the other borders.
BWaux = zeros (rows (BW) + 1, columns (BW) + 1);
for r = 1 : rows(BW)
for c = 1 : columns (BW)
BWaux (r + 1, c + 1) = BW (r, c);
endfor
endfor
eul = sum (applylut (BWaux, lut) (:));
endfunction
%!demo
%! A=zeros(9,10);
%! A([2,5,8],2:9)=1;
%! A(2:8,[2,9])=1
%! bweuler(A)
%! # Euler number (objects minus holes) is 1-2=-1 in an 8-like object
%!test
%! A=zeros(10,10);
%! A(2:9,3:8)=1;
%! A(4,4)=0;
%! A(8,8)=0; # not a hole
%! A(6,6)=0;
%! assert(bweuler(A),-1);
%!# This will test if n=4 and n=8 behave differently
%!test
%! A=zeros(10,10);
%! A(2:4,2:4)=1;
%! A(5:8,5:8)=1;
%! assert(bweuler(A,4),2);
%! assert(bweuler(A,8),1);
%! assert(bweuler(A),1);
% $Log$
% Revision 1.3 2007/03/23 16:14:36 adb014
% Update the FSF address
%
% Revision 1.2 2007/01/04 23:41:47 hauberg
% Minor changes in help text
%
% Revision 1.1 2006/08/20 12:59:31 hauberg
% Changed the structure to match the package system
%
% Revision 1.2 2005/07/03 01:10:19 pkienzle
% Try to correct for missing newline at the end of the file
%
% Revision 1.1 2004/08/15 19:33:20 jmones
% bweuler: Calculates the Euler number of a binary image
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev