annotate Problems/private/thumbFromOp.m @ 57:3a58e70e8cbe

(none)
author idamnjanovic
date Mon, 14 Mar 2011 17:06:07 +0000
parents a8a32e130893
children
rev   line source
idamnjanovic@52 1 function P = thumbFromOp(op,m,n,sm,sn,grayscale)
idamnjanovic@52 2 % Output matrix P, of size m x n, sampled at
idamnjanovic@52 3 % sm x sn upper top
idamnjanovic@52 4
idamnjanovic@52 5 % Copyright 2008, Ewout van den Berg and Michael P. Friedlander
idamnjanovic@52 6 % http://www.cs.ubc.ca/labs/scl/sparco
idamnjanovic@52 7 % $Id: thumbFromOp.m 1040 2008-06-26 20:29:02Z ewout78 $
idamnjanovic@52 8
idamnjanovic@52 9 if nargin < 6, grayscale = 0; end
idamnjanovic@52 10
idamnjanovic@52 11 info = op([],0);
idamnjanovic@52 12
idamnjanovic@52 13 sm = min(info{1},sm);
idamnjanovic@52 14 sn = min(info{2},sn);
idamnjanovic@52 15 M = zeros(sm,sn);
idamnjanovic@52 16
idamnjanovic@52 17 for i=1:sn
idamnjanovic@52 18 v = zeros(info{2},1); v(i) = 1;
idamnjanovic@52 19 w = real(op(v,1));
idamnjanovic@52 20
idamnjanovic@52 21 M(:,i) = w(1:sm);
idamnjanovic@52 22 end
idamnjanovic@52 23
idamnjanovic@52 24 mn = min(min(M));
idamnjanovic@52 25 mx = max(max(M));
idamnjanovic@52 26 M = (M - mn) / (mx-mn);
idamnjanovic@52 27
idamnjanovic@52 28 idxm = floor(linspace(1,sm+1,m+1)); idxm = idxm(1:end-1);
idamnjanovic@52 29 idxn = floor(linspace(1,sn+1,n+1)); idxn = idxn(1:end-1);
idamnjanovic@52 30
idamnjanovic@52 31 if grayscale
idamnjanovic@52 32 P = 1-M(idxm,idxn);
idamnjanovic@52 33 else
idamnjanovic@52 34 clrmap = hsv;
idamnjanovic@52 35 M = 1 + round(M * (length(clrmap)-1));
idamnjanovic@52 36 P = zeros(m,n,3);
idamnjanovic@52 37 for j1=1:m
idamnjanovic@52 38 for j2=1:n
idamnjanovic@52 39 P(j1,j2,:) = clrmap(M(idxm(j1),idxn(j2)),:);
idamnjanovic@52 40 end
idamnjanovic@52 41 end
idamnjanovic@52 42 end