function h=imshow(arg1,arg2,arg3,arg4,arg5)
%IMSHOW	Display image data.
%	IMSHOW is used to display all types of images: indexed images,
%	intensity images, and RGB images.
%
%	IMSHOW(X,MAP) displays the indexed image A with the colormap MAP.
%	IMSHOW(I,N) displays the intensity image I with a gray scale
%	colormap of length N.
%	IMSHOW(R,G,B) displays the RGB image in the intensity matrices 
%	R,G,B with an approximate colormap based on uniform quantization.
%
%	IMSHOW(A) looks at the data in the matrix A to determine the
%	type of image (see ISIND, ISBW, and ISGRAY) and displays the result
%	with the current colormap.  If A isn't one of the image types, it
%	is displayed using IMAGESC.
%
%	IMSHOW(x,y,A,...) uses the vectors x,y to define the axis 
%	coordinates.
%
%	H = IMSHOW(...) returns a handle to the created image object.
%
%	See also IMAGE, IMAGESC.

%	Clay M. Thompson 5-12-93
%	Copyright (c) 1993 by The MathWorks, Inc.
%	$Revision: 1.17 $  $Date: 1993/10/14 23:01:20 $

if nargin<1, error('Not enough input arguments.'); end

% Determine how screen depths are reutrned.
c = computer;
useNew = 1;
if strcmp(c(1:2),'PC') | strcmp(c(1:2),'MA')
   s = [version '    ']; k = find(s<46 & s>58);
   if ~isempty(k), s = s(1:min(k)); end
   [ver,count,msg,next] = sscanf(s,'%f',1);
   if ver > 4.1,
     useNew = 1;
   elseif ver < 4.1,
     useNew = 0;
   else
     if s(next)>='a', useNew = 1; else useNew = 0; end
   end
end
   
cm = colormap;
if nargin==1, % imshow(a)
  if isgray(arg1),
    idx = (arg1*(size(cm,1)-1))+1;
    hh = image(idx);
    set(hh,'UserData',[0 1])
  elseif isind(arg1),
    hh = image(arg1);
  else
    hh = imagesc(arg1);
  end
  colormap(cm)

elseif nargin==2, % imshow(a,cm) or imshow(I,n)
  if prod(size(arg2))==1,
    idx = (arg1*(arg2-1))+1;
    hh = image(idx); colormap(gray(arg2))
    set(hh,'UserData',[0 1])
  else
    hh = image(arg1); colormap(arg2)
  end

elseif nargin==3, % imshow(x,y,a) or imshow(r,g,b)
  if isgray(arg1) & isgray(arg2) & isgray(arg3) & ...
     all(size(arg1)==size(arg2)) & all(size(arg1)==size(arg3)), 
    sd = get(0,'screendepth');
    if ~useNew
       sd = min(8,sd);
    end
    if sd > 8  % 24-bit color
       [c,map] = rgb2ind(arg1,arg2,arg3);
    else
       [mp1 mp2 mp3] = meshgrid(0:.2:1,0:.2:1,0:.2:1);
       map = [mp1(:) mp2(:) mp3(:)];
       c = dither(arg1,arg2,arg3,map); % Uniform quantization, max. 216 colors
    end
    hh = image(c); colormap(map)
  else
    if isgray(arg3),
      idx = (arg3*(size(cm,1)-1))+1;
      x = [min(min(arg1)) max(max(arg1))];
      y = [min(min(arg2)) max(max(arg2))];
      hh = image(x,y,idx);
      set(hh,'UserData',[0 1])
    elseif isind(arg3),
      x = [min(min(arg1)) max(max(arg1))];
      y = [min(min(arg2)) max(max(arg2))];
      hh = image(x,y,arg3);
    else
      x = [min(min(arg1)) max(max(arg1))];
      y = [min(min(arg2)) max(max(arg2))];
      hh = imagesc(x,y,arg3);
    end
    colormap(cm)
  end

elseif nargin==4, % imshow(x,y,a,cm) or imshow(x,y,I,n)
  if prod(size(arg4))==1,
    idx = (arg3*(arg4-1))+1;
    x = [min(min(arg1)) max(max(arg1))];
    y = [min(min(arg2)) max(max(arg2))];
    hh = image(x,y,idx); colormap(gray(arg4))
    set(hh,'UserData',[0 1])
  else
    x = [min(min(arg1)) max(max(arg1))];
    y = [min(min(arg2)) max(max(arg2))];
    hh = image(x,y,arg3); colormap(arg4)
  end
  
elseif nargin==5, % imshow(x,y,r,g,b)
  if any(size(arg3)~=size(arg4)) | any(size(arg3)~=size(arg5)),
    error('The R,G, and B matrices must all be the same size.');
  end
  sd = get(0,'screendepth');
  if ~useNew
      sd = min(8,sd);
  end
  if sd > 8  % 24-bit color
     [c,map] = rgb2ind(arg3,arg4,arg5);
  else
     [mp1 mp2 mp3] = meshgrid(0:.2:1,0:.2:1,0:.2:1);
     map = [mp1(:) mp2(:) mp3(:)];
     c = dither(arg3,arg4,arg5,map); % Uniform quantization, max. 216 colors
  end
  x = [min(min(arg1)) max(max(arg1))];
  y = [min(min(arg2)) max(max(arg2))];
  hh = image(x,y,c); colormap(map)

end
axis image,set(gca,'xticklabels','','yticklabels','');

if nargout > 0
	h = hh;
end
