Skip to content

Commit d76befd

Browse files
committed
added hue example images
1 parent 7ea8e8f commit d76befd

File tree

8 files changed

+117
-2
lines changed

8 files changed

+117
-2
lines changed

examples/computeColor.m

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
function img = computeColor(u,v)
2+
3+
% computeColor color codes flow field U, V
4+
5+
% According to the c++ source code of Daniel Scharstein
6+
7+
8+
% Author: Deqing Sun, Department of Computer Science, Brown University
9+
10+
% $Date: 2007-10-31 21:20:30 (Wed, 31 Oct 2006) $
11+
12+
% Copyright 2007, Deqing Sun.
13+
%
14+
% All Rights Reserved
15+
%
16+
% Permission to use, copy, modify, and distribute this software and its
17+
% documentation for any purpose other than its incorporation into a
18+
% commercial product is hereby granted without fee, provided that the
19+
% above copyright notice appear in all copies and that both that
20+
% copyright notice and this permission notice appear in supporting
21+
% documentation, and that the name of the author and Brown University not be used in
22+
% advertising or publicity pertaining to distribution of the software
23+
% without specific, written prior permission.
24+
%
25+
% THE AUTHOR AND BROWN UNIVERSITY DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
26+
% INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
27+
% PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR OR BROWN UNIVERSITY BE LIABLE FOR
28+
% ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29+
% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
30+
% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
31+
% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32+
33+
nanIdx = isnan(u) | isnan(v);
34+
u(nanIdx) = 0;
35+
v(nanIdx) = 0;
36+
37+
colorwheel = makeColorwheel();
38+
ncols = size(colorwheel, 1);
39+
40+
rad = sqrt(u.^2+v.^2);
41+
42+
a = atan2(-v, -u)/pi;
43+
44+
fk = (a+1) /2 * (ncols-1) + 1; % -1~1 maped to 1~ncols
45+
46+
k0 = floor(fk); % 1, 2, ..., ncols
47+
48+
k1 = k0+1;
49+
k1(k1==ncols+1) = 1;
50+
51+
f = fk - k0;
52+
53+
for i = 1:size(colorwheel,2)
54+
tmp = colorwheel(:,i);
55+
col0 = tmp(k0)/255;
56+
col1 = tmp(k1)/255;
57+
col = (1-f).*col0 + f.*col1;
58+
59+
idx = rad <= 1;
60+
col(idx) = 1-rad(idx).*(1-col(idx)); % increase saturation with radius
61+
62+
col(~idx) = col(~idx)*0.75; % out of range
63+
64+
img(:,:, i) = uint8(floor(255*col.*(1-nanIdx)));
65+
end;
66+
67+
%%
68+
function colorwheel = makeColorwheel()
69+
70+
% color encoding scheme
71+
72+
% adapted from the color circle idea described at
73+
% http://members.shaw.ca/quadibloc/other/colint.htm
74+
75+
76+
RY = 15;
77+
YG = 6;
78+
GC = 4;
79+
CB = 11;
80+
BM = 13;
81+
MR = 6;
82+
83+
ncols = RY + YG + GC + CB + BM + MR;
84+
85+
colorwheel = zeros(ncols, 3); % r g b
86+
87+
col = 0;
88+
%RY
89+
colorwheel(1:RY, 1) = 255;
90+
colorwheel(1:RY, 2) = floor(255*(0:RY-1)/RY)';
91+
col = col+RY;
92+
93+
%YG
94+
colorwheel(col+(1:YG), 1) = 255 - floor(255*(0:YG-1)/YG)';
95+
colorwheel(col+(1:YG), 2) = 255;
96+
col = col+YG;
97+
98+
%GC
99+
colorwheel(col+(1:GC), 2) = 255;
100+
colorwheel(col+(1:GC), 3) = floor(255*(0:GC-1)/GC)';
101+
col = col+GC;
102+
103+
%CB
104+
colorwheel(col+(1:CB), 2) = 255 - floor(255*(0:CB-1)/CB)';
105+
colorwheel(col+(1:CB), 3) = 255;
106+
col = col+CB;
107+
108+
%BM
109+
colorwheel(col+(1:BM), 3) = 255;
110+
colorwheel(col+(1:BM), 1) = floor(255*(0:BM-1)/BM)';
111+
col = col+BM;
112+
113+
%MR
114+
colorwheel(col+(1:MR), 3) = 255 - floor(255*(0:MR-1)/MR)';
115+
colorwheel(col+(1:MR), 1) = 255;
Loading
Loading
Loading
Loading
Loading
Loading

examples/vis_hue.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
% The script requires the training sequences of the MPI Sintel dataset (http://sintel.is.tue.mpg.de/).
2-
% flowToColor is originally part of the MPI Sintel's bundler.
2+
% flowToColor and computeColor are originally part of the MPI Sintel's bundler.
33
% The script has originally been used to produce visualizations for https://github.com/vadimkantorov/mpegflow/blob/master/README.md, but you could use it on other videos by adjusting VIDEO_PATH
44

55
VIDEO_PATH = 'mpi_sintel_final_alley_1.avi';
@@ -15,7 +15,7 @@
1515
if isempty(frameIndex_rows_cols)
1616
break
1717
end
18-
18+
1919
dxdy = fscanf(f, '%d ', fliplr(frameIndex_rows_cols(2:end)'))';
2020
flow = cat(3, dxdy(1:size(dxdy, 1) / 2, :), dxdy(size(dxdy, 1) / 2 + 1 : end, :));
2121
img = flowToColor(flow);

0 commit comments

Comments
 (0)