forked from ldci/redCV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvolution2.red
More file actions
110 lines (93 loc) · 2.17 KB
/
Copy pathconvolution2.red
File metadata and controls
110 lines (93 loc) · 2.17 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
Red [
Title: "Test images convolution Red VID "
Author: "ldci"
File: %convolution2.red
Needs: 'View
]
fileName: ""
isFile: false
;required libs
#include %../../libs/core/rcvCore.red
#include %../../libs/matrix/rcvMatrix.red
#include %../../libs/tools/rcvTools.red
#include %../../libs/imgproc/rcvImgProc.red
identity: [0.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 0.0]
highPass: [-1.0 0.0 -1.0
0.0 8.0 0.0
-1.0 0.0 -1.0]
lowPass: [1.0 1.0 1.0
1.0 1.0 1.0
1.0 1.0 1.0]
; same as low pass * 1/9
{lowPass2: [0.111 0.111 0.111
0.111 0.111 0.111
0.111 0.111 0.111]}
rimg: rcvCreateImage 512x512
dst: rcvCreateImage 512x512
sumW: 0
factor: 1.0
delta: 0.0
op: 1
loadImage: does [
sb1/data: ""
isFile: false
canvas/image/rgb: black
tmp: request-file
if not none? tmp [
fileName: to string! to-file tmp
win/text: rejoin ["redCV Convolution: " fileName]
rimg: rcvLoadImage tmp
dst: rcvLoadImage tmp
canvas/image: dst
isFile: true
op: 1
dp/selected: 1
]
]
img-convolve: func [num [integer!]] [
sb1/text: copy ""
switch num [
1 [rcvConvolve rimg dst identity factor delta]
2 [t1: now/time/precise
rcvConvolve rimg dst lowPass factor delta
sb1/text: rejoin [round/to third now/time/precise - t1 0.001 " sec"]
]
3 [t1: now/time/precise
rcvConvolve rimg dst highPass factor delta
sb1/text: rejoin [round/to third now/time/precise - t1 0.001 " sec"]
]
]
]
view win: layout [
title "redCV Convolution"
origin 10x10 space 10x10
button "Load" [loadImage]
dp: drop-down 120x24 data [
"Identity" "Low Pass Filter" "High Pass Filter"
] select 1
on-change [op: face/selected if isFile [img-convolve op]]
text "Rendered in: " sb1: field 100x24
pad 35x0
button "Quit" [quit]
return
text 40 "Factor"
sl1: slider 100 [
sumW: to-integer face/data * 256
sumT/text: form sumW
either sumW > 0 [factor: 1.0 / sumW] [factor: 1.0]
ft/data: form factor
if isFile [img-convolve op]
]
sumT: field 40 "0"
ft: field 40 "1.0"
text 40 "Delta"
sl2: slider 140 [delta: 0.0 + (face/data * 256.0)
dt/data: form delta
if isFile [img-convolve op]
]
dt: field 40 "0.0"
return
canvas: base 512x512 dst
]