-
Notifications
You must be signed in to change notification settings - Fork 22
/
showimg.m
43 lines (36 loc) · 830 Bytes
/
showimg.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
function h=showimg(x,y,A)
% Display an image
%
% Usage h=showimg(x,y,A)
%
% Very similar to imshow, but makes it easier to pass pixel coordinates.
%
% Example usage:
% A = imread('cameraman.tif');
% A(1,1,3)=0; %set the green and blue channels to all zeros.
% x = (1:size(A,2))*10+100;
% y = (size(A,1):-1:1)*10+100;
% showimg(x,y,A);
% axis on
%
% Aslak Grinsted 2016
if nargin==1
A=x;
x=1:size(A,2);
y=1:size(A,1);
end
if ~isa(A,'uint8')
A=A-min(A(:));
A=uint8(A*255.49./max(A(:)));
end
if size(A,3)==1
A=repmat(A,[1 1 3]); %this is to ensure that it does not interfere with CAXIS.
end
h=image(A,'XData',x,'YData',y,'CDataMapping','scaled'); %the cdatamapping is a workaround for a bug in R2014+
axis equal tight xy off
if nargin==1
axis ij
end
if nargout==0
clearvars h
end