-
Notifications
You must be signed in to change notification settings - Fork 0
/
show.m
116 lines (100 loc) · 3.95 KB
/
show.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
% SHOW - Displays an image with the right size and colors and with a title.
%
% Usage: h = show(im, figNo, title)
%
% Arguments: im - Either a 2 or 3D array of pixel values or the name
% of an image file;
% figNo - Optional figure number to display image in. If
% figNo is 0 the current figure or subplot is
% assumed.
% title - Optional string specifying figure title
%
% Returns: h - Handle to the figure. This allows you to set
% additional figure attributes if desired.
%
% The function displays the image, automatically setting the colour map to
% grey if it is a 2D image, or leaving it as colour otherwise, and setting
% the axes to be 'equal'. The image is also displayed as 'TrueSize', that
% is, pixels on the screen match pixels in the image (if it is possible
% to fit it on the screen, otherwise MATLAB rescales it to fit).
%
% Unless you are doing a subplot (figNo==0) the window is sized to match
% the image, leaving no border, and hence saving desktop real estate.
%
% If figNo is omitted a new figure window is created for the image. If
% figNo is supplied, and the figure exists, the existing window is reused to
% display the image, otherwise a new window is created. If figNo is 0 the
% current figure or subplot is assumed.
% Copyright (c) 2000-2007 Peter Kovesi
% School of Computer Science & Software Engineering
% The University of Western Australia
% http://www.csse.uwa.edu.au/
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% The Software is provided "as is", without warranty of any kind.
% October 2000 Original version
% March 2003 Mods to alow figure name in window bar and allow for subplots.
% April 2007 Proper recording and restoring of MATLAB warning state.
% September 2008 Octave compatible
function h = show(im, figNo, usecbar, Title)
Octave = exist('OCTAVE_VERSION') ~= 0; % Are we running under Octave?
s = warning('query','all'); % Record existing warning state.
warning('off'); % Turn off warnings that might arise if image
% has to be rescaled to fit on screen
if(~exist('usecbar','var'))
usecbar = 1;
end
if nargin <= 3
if ~isnumeric(im) & ~islogical(im) % Guess that an image name has
% been supplied
Title = im;
im = imread(im);
else
Title = inputname(1); % Get variable name of image data
end
end
newWindow = 1;
if nargin >= 2
if figNo % We have a valid figure number
figure(figNo); % Reuse or create a figure window with
% this number
if ~Octave
subplot('position',[0 0 1 1]); % Use the whole window
end
else
newWindow=0; % figNo == 0
end
else
figNo = figure; % Create new figure window
if ~Octave
subplot('position',[0 0 1 1]); % Use the whole window
end
end
if ndims(im) == 2 % Display as greyscale
imagesc(im)
if(usecbar)colorbar;end
%colormap('gray');
else
imshow(im) % Display as RGB
end
if newWindow
axis('image'), axis('off')
set(figNo,'name', [' ' Title])
if ~Octave
[rows cols ch] = size(im);
truesize(figNo,[rows cols]);
end
else % Assume we are trying to do a subplot
axis('image'), axis('off')
title(Title) % Use a title rather than rename the figure
end
if nargout == 1
h = figNo;
end
warning(s); % Restore warnings