On 1 November 2011 21:14, Adrián del Pino <delpinonavarr...@gmail.com> wrote:
> In the following sentences
>
> img=imread("segm_Basketball12gris.tif");
> [counts,x]=imhist(img);
>
> counts returns the correct values 323 and 109 but in the 1st and the 129th
> bins when the gray values are 11 and 36.
>
> Greetings,
>                 Adrián

Hi Adrián

apologies for taking so long to come around this. I believe I may have
fixed the issue. Could you please test if the attached filw works for
you? I fixed several other issues with it.

One thing to note, the values of all pixels with intensity 11 will
show up on position 12 since the first bin is for pixels with
intensity 0.

Please report back wether it works or not.

Carnë
## Copyright (C) 1999,2000  Kai Habel
## Copyright (C) 2011 Carnë Draug <carandraug+...@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.
##
## 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} {} imhist (@var{I})
## @deftypefnx {Function File} {} imhist (@var{I}, @var{n})
## @deftypefnx {Function File} {} imhist (@var{X}, @var{cmap})
## @deftypefnx {Function File} {[@var{n,x}] = } imhist (@dots{})
## Shows the histogram of an image @var{I}.
##
## The second argument can either be @var{n}, a scalar that specifies the number
## of bins; or @var{cmap}, a colormap in whichh case @var{I} is expected to be
## an indexed image. If not specified, @var{n} defauls to 2 for binary images,
## and 256 for grayscale images.
##
## @seealso{hist}
## @end deftypefn

## Author:	Kai Habel <kai.ha...@gmx.de>
## July 2000 : Paul Kienzle code simplification for hist() call.

function [nn, bins] = imhist (I, b)

  if (nargin < 1 || nargin > 2)
    print_usage();

  elseif (nargin == 1)
    if (islogical(I))
      bins = 0:1;
    else
      bins = 0:255;
    endif

  elseif (nargin == 2)
    ## A matrix with 3 columns is a colormap so...
    if (ismatrix (b) && columns (b) == 3)
      ## if using a colormap, image must be an indexed image
      if (!isind(I))
        error ("second argument is a colormap but image is not indexed");
      endif
      max_idx = max (I(:));
      bins    = 0:rows(b)-1;
      if (max_idx > bins(end))
        warning ("largest index exceedes length of colormap");
      endif
      bins 
    elseif (isnumeric (b) && isscalar (b) && fix(b) == b)
      bins = 0:b-1;
    else
      error ("second argument should be either a positive integer scalar or a colormap");
    endif
  endif

  if (nargout == 0)
    histc (I(:), bins);
  else
    [nn] = histc (I(:), bins);
  endif
  bins = bins';
  ## matlab returns one column (not row) for both outputs
endfunction
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to