octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: imread image sizing


From: Stefan van der Walt
Subject: Re: imread image sizing
Date: Fri, 12 Mar 2004 12:33:05 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031107 Debian/1.5-3

I wrote a patch to fix the zooming a while ago.  Maybe you'd find it useful:

http://www.octave.org/mailing-lists/bug-octave/2004/132

The encoding on that e-mail went horribly wrong, so I attach a version here as well.

Regards
Stéfan

Ross Vandegrift wrote:
On Wed, Mar 10, 2004 at 01:18:12PM -0600, John W. Eaton wrote:

scripts/image directory.  So now might be a good time for someone (but
not me -- I am busy enough with other projects) to start revising
Octave's image processing capabilities, preferably in a way that is
compatible with the other leading brand.  I have not looked to see
what is available in octave-forge, but that would be a good place to
start.


I was actually under the impression that all of Octave's image
processing came from octave-forge.  Shows what I know! ::-)

Depending on how much use it gets, I may fix the scaling problem I ran
into or clean up some of the octave-force stuff for inclusion.  Depends
on how much image processing is a part of this semester's numerics
class.


*** /tmp/imshow.m       2004-02-14 11:06:00.000000000 +0200
--- imshow.m    2004-02-24 00:25:24.000000000 +0200
***************
*** 18,59 ****
  ## 02111-1307, USA.
  
  ## -*- texinfo -*-
! ## @deftypefn {Function File} {} imshow (@var{x}, @var{map})
  ## @deftypefnx {Function File} {} imshow (@var{x}, @var{n})
  ## @deftypefnx {Function File} {} imshow (@var{i}, @var{n})
  ## @deftypefnx {Function File} {} imshow (@var{r}, @var{g}, @var{b})
! ## Display images.
  ##
! ## @code{imshow (@var{x})} displays an indexed image using the current
! ## colormap.
  ##
  ## @code{imshow (@var{x}, @var{map})} displays an indexed image using the
  ## specified colormap.
  ##
! ## @code{imshow (@var{i}, @var{n})} displays a gray scale intensity image.
  ##
  ## @code{imshow (@var{r}, @var{g}, @var{b})} displays an RGB image.
  ## @end deftypefn
  ## @seealso{image, imagesc, colormap, gray2ind, and rgb2ind}
  
  ## Author: Tony Richardson <address@hidden>
  ## Created: July 1994
  ## Adapted-By: jwe
  
! function imshow (a1, a2, a3)
  
!   if (nargin < 0 || nargin > 3)
!     usage ("imshow (args)");
!   elseif (nargin == 2)
!     if (length (a2) == 1)
!       [a1, a2] = gray2ind (a1, a2);
      endif
-     colormap (a2);
-   elseif (nargin == 3)
-     [a1, a2] = rgb2ind (a1, a2, a3);
-     colormap (a2);
    endif
  
!   image (a1);
  
  endfunction
--- 18,134 ----
  ## 02111-1307, USA.
  
  ## -*- texinfo -*-
! ## @deftypefn {Function File} {} imshow (@var{i})
! ## @deftypefnx {Function File} {} imshow (@var{x}, @var{map})
  ## @deftypefnx {Function File} {} imshow (@var{x}, @var{n})
  ## @deftypefnx {Function File} {} imshow (@var{i}, @var{n})
  ## @deftypefnx {Function File} {} imshow (@var{r}, @var{g}, @var{b})
! ## Display an image.
  ##
! ## @code{imshow (@var{x})} displays an intensity image, estimating the 
! ## number of gray levels.
  ##
  ## @code{imshow (@var{x}, @var{map})} displays an indexed image using the
  ## specified colormap.
  ##
! ## @code{imshow (@var{i}, @var{N})} displays a gray scale intensity image of
! ## N levels.
  ##
  ## @code{imshow (@var{r}, @var{g}, @var{b})} displays an RGB image.
+ ##
+ ## The string @code{truesize} can always be used as an optional
+ ## final argument to prevent automatic zooming of the image.
  ## @end deftypefn
+ ##
  ## @seealso{image, imagesc, colormap, gray2ind, and rgb2ind}
  
  ## Author: Tony Richardson <address@hidden>
  ## Created: July 1994
  ## Adapted-By: jwe
+ ## Modified: Stefan van der Walt <address@hidden>, 23/02/2004
+ ##           Added 'truesize' functionality.  Made function more           
+ ##           robust against different image scalings.  imshow(x)
+ ##           now ignores the current colormap.  Added unit tests
+ ##           and demos.
+ 
+ function imshow (varargin)
  
!   usage_str = "imshow (x) || imshow(x, map) || imshow(i, N) || imshow(r,g,b)";
  
!   if (nargin == 0 || nargin > 4)
!     usage (usage_str);
!   endif
!   
!   # count nr of matrix arguments
!   mvars = 0;
!   while (mvars < nargin) && ismatrix(varargin{mvars+1})
!     mvars++;
!   endwhile
!   
!   if (mvars < 1 || mvars > 3)
!     usage (usage_str);
!   endif
!   
!   ## all except imshow(r,g,b)
!   if (mvars != 3)
!     I = varargin{1};
!     if max(max(varargin{1})) <= 1
!       # image in [0-1]; scale to [0-255]
!       I = I * 255;
!       M = gray(256);
      endif
    endif
  
!   ## imshow(x)
!   if (mvars == 1)
!     ## grayscale image [0-N] -- estimate gray levels
!     N = 2^ceil( log2(max(max(I))) );
!     M = gray(N);
!     
!   ## imshow(x, map) or imshow(x, N)
!   elseif (mvars == 2)
!     M = varargin{2};
!     if isscalar(M)
!       M = gray(M);
!     endif
!     
!   ## imshow(r,g,b)
!   elseif (mvars == 3)
!     r = varargin{1}; g = varargin{2}; b = varargin{3};
!     if max(max([r; g; b])) > 1
!       # normalise to [0-1]
!       r = r/255;
!       g = g/255;
!       b = b/255;
!     endif
!     [I, M] = rgb2ind (r, g, b);
!   endif
!   
!   # check for 'truesize'
!   zoom = [];
!   for i = mvars+1:nargin
!     if isstr(varargin{i}) && strcmp(varargin{i}, 'truesize')
!       zoom = 1;
!     endif
!   endfor
! 
!   colormap(M);
!   image (I, zoom);
  
  endfunction
+ 
+ %!error imshow()                   # no arguments
+ %!error imshow(1,2,3,4,5)          # too many arguments
+ %!error imshow([1], [2], [3], [4]) # too many matrix arguments
+ %!error imshow('image.png')        # filename not accepted as argument
+ 
+ %!demo
+ %!  imshow( loadimage('default.img') );
+ 
+ %!demo
+ %!  I = loadimage('default.img');
+ %!  imshow(I, 'truesize')
+ 
+ %!demo
+ %!  [I, M] = loadimage('default.img');
+ %!  imshow(I, M);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]