Skip to content

Commit 65733bf

Browse files
committed
show.m: add possibility to annotate image display
1 parent d3b03d4 commit 65733bf

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

src/@Image/show.m

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
function varargout = show(obj, varargin)
2-
% Shows image on current axis
2+
% Shows image on current axis.
33
%
4-
% Image is displayed in its physical extent, based on image origin and
5-
% spacing.
4+
% Image is displayed in its physical extent, based on image Origin and
5+
% Spacing properties.
66
%
77

8+
%% parse input arguments
9+
10+
% default values
11+
showTitle = true;
12+
showAxisNames = true;
13+
14+
% parse options
15+
options = {};
16+
while length(varargin) > 1
17+
if strcmp(varargin{1}, 'showAxisNames')
18+
else
19+
options = [options, varargin(1:2)]; %#ok<AGROW>
20+
end
21+
varargin(1:2) = [];
22+
end
23+
% options = varargin;
24+
25+
826
% Check image dimension: should be 2, or can be squeezed to 2.
927
if obj.Dimension ~= 2
1028
% compute number of image dimension
@@ -19,8 +37,7 @@
1937
end
2038
end
2139

22-
options = varargin;
23-
40+
%% Prepare data
2441
data = getDisplayData(obj);
2542

2643
% if double, adjust grayscale extent
@@ -32,6 +49,9 @@
3249
xdata = xData(obj);
3350
ydata = yData(obj);
3451

52+
53+
%% Display data
54+
3555
% display image with approriate spatial reference
3656
h = imshow(data, 'XData', xdata, 'YData', ydata, options{:});
3757

@@ -44,11 +64,29 @@
4464
xlim(xl); ylim(yl);
4565

4666

67+
%% Annotate
68+
69+
% show title
70+
if ~isempty(obj.Name) && showTitle
71+
title(obj.Name);
72+
end
73+
74+
% show axis names
75+
if ~isempty(obj.AxisNames) && length(obj.AxisNames) >= 2 && showAxisNames
76+
xlabel(obj.AxisNames{1})
77+
ylabel(obj.AxisNames{2})
78+
end
79+
80+
81+
%% post-processing
82+
4783
% eventually returns handle to image object
4884
if nargout > 0
4985
varargout = {h};
5086
end
5187

88+
89+
%% Inner functions
5290
function options = updateDisplayRangeOptions(data, options)
5391

5492
% compute grayscale extent within image

0 commit comments

Comments
 (0)