function h = scatterim2(X,Y,images,scales)
% Make a 2-D scatterplot using one or several images as glyphs
%
% h = scatterim2(X,Y,images,scales)
%
% Images are painted at the locations of pairs (x,y) from the vectors X and
% Y. Images can be either a cell array of images or a single image. An
% image can either be scalar valued or RGB. The images and the handle h
% behaves as for individual images generated by image3, see "help image 3"
% for more explanations.
%
% SEE ALSO: slice3, image3
%
%
h = zeros(size(X,1),1);
for k = 1:length(X)
if iscell(images)
im = images{k};
else
im = images;
end
if length(scales)>1
scale = scales(k);
else
scale = scales;
end
sz = max(size(im,1),size(im,2));
dx = scale/sz;
dy = scale/sz;
T = [dx, 0, X(k)-dx*(size(im,1)+1)/2;
0, dy, Y(k)-dy*(size(im,2)+1)/2;
0, 0, -1e-9; % This was necessary to make the plots nice...
0, 0, 1];
h(k) = image3(im, T);
end