annotate util/sparco utils/thumbPlot.m @ 247:ecce33192fcc tip

Added tag ver_2.1 for changeset cef4500b936f
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 31 Oct 2012 12:24:44 +0000
parents 62f20b91d870
children
rev   line source
ivan@77 1 function P = thumbPlot(P,x,y,color)
ivan@77 2
ivan@77 3 % Copyright 2008, Ewout van den Berg and Michael P. Friedlander
ivan@77 4 % http://www.cs.ubc.ca/labs/scl/sparco
ivan@77 5 % $Id: thumbPlot.m 1040 2008-06-26 20:29:02Z ewout78 $
ivan@77 6
ivan@77 7 m = size(P,1);
ivan@77 8 n = size(P,2);
ivan@77 9 if (size(P,3) == 0) & (length(color) == 3)
ivan@77 10 % Convert to gray-scale
ivan@77 11 color = 0.30*color(1) + 0.59*color(2) + 0.11*color(3);
ivan@77 12 end
ivan@77 13
ivan@77 14 mnx = min(x); % Minimum x
ivan@77 15 mxx = max(x); % Maximum x
ivan@77 16 mny = min(y); % Minimum y
ivan@77 17 mxy = max(y); % Maximum y
ivan@77 18 dy = (mxy - mny) * 0.1; % Offset on vertical axis
ivan@77 19 sx = (mxx - mnx) * 1.0; % Scale of horizontal axis
ivan@77 20 sy = (mxy - mny) * 1.2; % Scale of vertical axis
ivan@77 21
ivan@77 22 if (sx < 1e-6), sx = 1; end
ivan@77 23 if (sy < 1e-6), sy = 1; end
ivan@77 24
ivan@77 25 for i=1:length(x)-1
ivan@77 26 x0 = floor(1 + (n-1) * (x(i ) - mnx) / sx);
ivan@77 27 x1 = floor(1 + (n-1) * (x(i+1) - mnx) / sx);
ivan@77 28 y0 = floor( (n-1) * (y(i ) - mny + dy) / sy);
ivan@77 29 y1 = floor( (n-1) * (y(i+1) - mny + dy) / sy);
ivan@77 30
ivan@77 31 samples = 1+2*max(abs(x1-x0)+1,abs(y1-y0)+1);
ivan@77 32 c = linspace(0,1,samples);
ivan@77 33 idx = round((1-c)*x0 + c*x1);
ivan@77 34 idy = n - round((1-c)*y0 + c*y1);
ivan@77 35 for j=1:samples
ivan@77 36 P(idy(j),idx(j),:) = color;
ivan@77 37 end
ivan@77 38 end