MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / emboss

Function emboss

examples/image_processing/filters.cpp:157–197  ·  view source on GitHub ↗

* azimuth range is [0-360] * elevation range is [0-180] * depth range is [1-100] * Note: this function has been tailored after * the emboss implementation in GIMP editor **/

Source from the content-addressed store, hash-verified

155 * the emboss implementation in GIMP editor
156 **/
157array emboss(const array &input, float azimuth, float elevation, float depth) {
158 if (depth < 1 || depth > 100) {
159 printf("Depth should be in the range of 1-100");
160 return input;
161 }
162 static float x[3] = {-1, 0, 1};
163 static array hg(3, x);
164 static array vg = hg.T();
165
166 array in = input;
167 if (in.dims(2) > 1)
168 in = colorSpace(input, AF_GRAY, AF_RGB);
169 else
170 in = input;
171
172 // convert angles to radians
173 float phi = elevation * af::Pi / 180.0f;
174 float theta = azimuth * af::Pi / 180.0f;
175
176 // compute light pos in cartesian coordinates
177 // and scale with maximum intensity
178 // phi will effect the amount of we intend to put
179 // on a pixel
180 float pos[3];
181 pos[0] = 255.99f * cos(phi) * cos(theta);
182 pos[1] = 255.99f * cos(phi) * sin(theta);
183 pos[2] = 255.99f * sin(phi);
184
185 // compute gradient vector
186 array gx = convolve(in, vg);
187 array gy = convolve(in, hg);
188
189 float pxlz = (6 * 255.0f) / depth;
190 array zdepth = constant(pxlz, gx.dims());
191 array vdot = gx * pos[0] + gy * pos[1] + pxlz * pos[2];
192 array outwd = vdot < 0.0f;
193 array norm = vdot / sqrt(gx * gx + gy * gy + zdepth * zdepth);
194
195 array color = outwd * 0.0f + (1 - outwd) * norm;
196 return color;
197}
198
199int main(int argc, char **argv) {
200 try {

Callers 1

mainFunction · 0.85

Calls 8

colorSpaceFunction · 0.85
cosFunction · 0.85
sinFunction · 0.85
constantFunction · 0.85
sqrtFunction · 0.85
TMethod · 0.80
convolveFunction · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected