-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter-feComponentTransfer.Rmd
More file actions
executable file
·213 lines (176 loc) · 6.16 KB
/
filter-feComponentTransfer.Rmd
File metadata and controls
executable file
·213 lines (176 loc) · 6.16 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
---
title: "feComponentTransfer"
output:
html_document:
toc: true
theme: united
---
```{r, echo=FALSE}
stopifnot(require(svgR, quietly=TRUE))
```
## feComponentTransfer
Colors can also be remapped using feComponentTransfer and the components feFuncR, feFuncG, feFuncB, feFuncA. The feFuncX's correspond to the
Red, Green, Blue, and Alpha channels. Each channel has a value between between 0 and 1 which can be reassinged using the component transfers.
There are four types of color component transfers:
- **table**: Reassigns the colors according to a piece-wise continous linear function that is specified by a "table"" values of points. The points are assumend to form a uniform partion of [0,1] so only the values need to be specified. (Using linear interpolation of the values between the points)
- **linear** Similar to table, but with only 2 points. The function is specifed using the slope and intercept
- **discrete** Reassigns the colors according to a step function that is specified by a "table"" of points. Again the points are assumed to be a uniform partition of [0,1], so only the values need be specified in the "table"." (Between points, the output is the value of the nearest point.
- **gamma** The value is given by
$C_{out} = \alpha \times C_{in}^\gamma + \beta$
#### feComponentTransfer: Table
We illustrate this with a simple example that interchanges the colors blue and red of a color spectrum.
```{r, echo=T, results="asis"}
WH=c(800, 200) # window rect
colors=c('red','blue')
svgR( wh=WH, stroke="black",
rect(wh=c(.6,.3)*WH, xy=c(.2,0)*WH,
fill=linearGradient(colors=colors)
),
rect(wh=c(.6,.3)*WH, xy=c(.2,.3)*WH,
fill=linearGradient(colors=colors),
filter=filter(
feComponentTransfer(
feFuncR( type="table", tableValues="1 0"),
feFuncB( type="table", tableValues="1 0 ")
)
)
),
text('original', xy=c(20,1.5*WH[2])),
text('transfered', xy=c(20,4.5*WH[2])),
text('feComponentTransfer using type="table"', cxy=c(.5,.8)*WH)
)
```
#### feComponentTransfer: Linear
```{r, echo=T, results="asis"}
WH=c(800, 200) # window rect
colors=c('red','blue')
svgR( wh=WH, stroke="black",
rect(wh=c(.6,.3)*WH, xy=c(.2,0)*WH,
fill=linearGradient(colors=colors)
),
rect(wh=c(.6,.3)*WH, xy=c(.2,.3)*WH,
fill=linearGradient(colors=colors),
filter=filter(
feComponentTransfer(
feFuncR( type="linear", intercept=1, slope=-1),
feFuncB( type="linear", intercept=1, slope=-1)
)
)
),
text('original', xy=c(20,1.5*WH[2])),
text('transfered', xy=c(20,4.5*WH[2])),
text('feComponentTransfer using type="linear"', cxy=c(.5,.8)*WH)
)
```
#### feComponentTransfer: Discrete
```{r, echo=T, results="asis"}
WH=c(800, 200) # window rect
colors=c('red','blue')
svgR( wh=WH, stroke="black",
rect(wh=c(.6,.3)*WH, xy=c(.2,0)*WH,
fill=linearGradient(colors=colors)
),
rect(wh=c(.6,.3)*WH, xy=c(.2,.3)*WH,
fill=linearGradient(colors=colors),
filter=filter(
feComponentTransfer(
feFuncR( type="discrete", tableValues="1 0"),
feFuncB( type="discrete", tableValues="1 0 ")
)
)
),
text('original', xy=c(20,1.5*WH[2])),
text('transfered', xy=c(20,4.5*WH[2])),
text('feComponentTransfer using type="discrete"', cxy=c(.5,.8)*WH)
)
```
#### feComponentTransfer: Gamma exponent=1
```{r, echo=T, results="asis"}
WH=c(800, 200) # window rect
colors=c('red','blue')
svgR( wh=WH, stroke="black",
rect(wh=c(.6,.3)*WH, xy=c(.2,0)*WH,
fill=linearGradient(colors=colors)
),
rect(wh=c(.6,.3)*WH, xy=c(.2,.3)*WH,
fill=linearGradient(colors=colors),
filter=filter(
feComponentTransfer(
feFuncR( type="gamma", offset=1, amplitude=-1, exponent=1),
feFuncB( type="gamma", offset=1, amplitude=-1, exponent=1)
)
)
),
text('original', xy=c(20,1.5*WH[2])),
text('transfered', xy=c(20,4.5*WH[2])),
text('feComponentTransfer using type="gamma"', cxy=c(.5,.8)*WH)
)
```
#### feComponentTransfer: Gamma, exponent=10
```{r, echo=T, results="asis"}
WH=c(800, 200) # window rect
colors=c('red','blue')
svgR( wh=WH, stroke="black",
rect(wh=c(.6,.3)*WH, xy=c(.2,0)*WH,
fill=linearGradient(colors=colors)
),
rect(wh=c(.6,.3)*WH, xy=c(.2,.3)*WH,
fill=linearGradient(colors=colors),
filter=filter(
feComponentTransfer(
feFuncR( type="gamma", offset=1, amplitude=-1, exponent=2),
feFuncB( type="gamma", offset=1, amplitude=-1, exponent=2)
)
)
),
text('original', xy=c(20,1.5*WH[2])),
text('transfered', xy=c(20,4.5*WH[2])),
text('feComponentTransfer using type="table"', cxy=c(.5,.8)*WH)
)
```
###feComponentTransfer: Inverting the grey scale
```{r, echo=T, results="asis"}
WH=c(800, 200) # window rect
colors=c('red','blue')
svgR( wh=WH, stroke="black",
rect(wh=c(.6,.3)*WH, xy=c(.2,0)*WH,
fill=linearGradient(colors=colors)
),
rect(wh=c(.6,.3)*WH, xy=c(.2,.3)*WH,
fill=linearGradient(colors=colors),
filter=filter(
feComponentTransfer(
feFuncR( type="table", tableValues="1 0"),
feFuncG( type="table", tableValues="1 0"),
feFuncB( type="table", tableValues="1 0 ")
)
)
),
text('original', xy=c(20,1.5*WH[2])),
text('transfered', xy=c(20,4.5*WH[2])),
text('feComponentTransfer using type="table"', cxy=c(.5,.8)*WH)
)
```
#### feComponentTransfer Applied to a Spectrum
```{r, echo=T, results="asis"}
WH=c(800, 100) # window rect
svgR( wh=WH,
lapply(seq(from=1, to=0, by=-.05),
function(i){
rect(xy=c(i*800,10), wh=c(32,96), fill=
linearGradient( xy1=c(0,0), xy2=c(0,1),
colors=c('red','yellow','green','blue')
),
filter=filter(
feComponentTransfer(
feFuncR(type="linear", slope=i, intercept=1-i),
feFuncG(type="linear", slope=1, intercept=0),
feFuncB(type="linear", slope=1-i, intercept=i),
feFuncA(type="linear", slope=0, intercept=1)
)
)
)
}
)
)
```