1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
% function RGB=showmask(V,M,hue);
% Input:
% V = image
% M = nonnegative mask
% hue = a number in [0,1], red,yellow,green,cyan,...,red
% a char, 'r','g','b','y','c','m'
% or a matrix of the same size of image
% eg. hue = mask1 * 0.7 + mask2 * 1;
%
% Output:
% RGB = an RGB image with V as shades and M as saturated hues
% If no output is required, this image is displayed.
% Stella X. YU, 2000. Based on Jianbo Shi's version.
function RGB=showmask(V,M,hue);
if nargin<3 | isempty(hue),
hue = 0;
end
if ischar(hue),
switch hue,
case 'r', hue = 1.0;
case 'g', hue = 0.3;
case 'b', hue = 0.7;
case 'y', hue = 0.15;
case 'c', hue = 0.55;
case 'm', hue = 0.85;
end
end
V=V-min(V(:));
V=V/max(V(:));
V=.25+0.75*V; %brighten things up a bit
M = double(M);
M = M-min(M(:));
M = M/max(M(:));
H = hue+zeros(size(V));
S = M;
RGB = hsv2rgb(H,S,V);
if nargout>0,
return;
end
hold off; image(RGB); axis('image');
s = cell(1,2);
if isempty(inputname(1)),
s{1} = 'image';
else
s{1} = inputname(1);
end
if isempty(inputname(2)),
s{2} = 'mask';
else
s{2} = inputname(2);
end
title(sprintf('%s and colored %s',s{1},s{2}));
if nargout==0,
clear RGB;
end
|