File: ef230-2023-08/www/examples/image_marker_example.m Download
function main
% example of how to plot images as 'markers' on a curve
% UTK EF 230 May, 2011
clear all; close all; clc;
% anon function to make a complete URL
imgurl = @(n)sprintf('http://ef.engr.utk.edu/c/efd/pix/%s_th.jpg',n);
% list of URLS
imglist = { imgurl('wschlete')
            imgurl('walehunt')
            imgurl('hphilli5')
            imgurl('pritter')
            imgurl('rgraha11') };

% arbitrary x and y values
x = linspace(0,2*pi,20);
y = sin(x);

% set up figure
figure(1);
set(gca,'ydir','reverse');
axis equal;
hold on;

% plot them
plotimg(x,y,imglist,0.005);
% plot dots for reference
plot(x,y,'ro','markerfacecolor','r','markersize',5);

function plotimg(x,y,imglist,scale)
% input: x,y - coordinates
%        imglist - cell array of image file names or urls
%        scale - scale factor

% load images and make them all the same height
numimg = length(imglist);
for i=1:numimg
    im{i} = imread(imglist{i}); % read it in
    im{i} = imresize(im{i},[100 NaN]); % resize so it is 100 pixels high
    w2(i) = size(im{i},2) * scale / 2; % width/2
    h2(i) = size(im{i},1) * scale / 2; % height/2
end

% show images
j = 0; % image index
for i=1:length(x)
    j = j+1;
    if j > numimg; j=1; end  % re-use images if needed
    xb = [x(i)-w2(j) x(i)+w2(j)];  % x boundaries
    yb = [y(i)-h2(j) y(i)+h2(j)];  % y boundaries
    image(xb,yb,im{j});
end

return