Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cuttlefish
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
squidworks
cuttlefish
Commits
2b5f62c4
Commit
2b5f62c4
authored
5 years ago
by
Jake Read
Browse files
Options
Downloads
Patches
Plain Diff
does it with color
parent
4fee2244
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
hunks/adhoc/correlate.js
+51
-6
51 additions, 6 deletions
hunks/adhoc/correlate.js
with
51 additions
and
6 deletions
hunks/adhoc/correlate.js
+
51
−
6
View file @
2b5f62c4
...
@@ -14,7 +14,7 @@ import {
...
@@ -14,7 +14,7 @@ import {
let
computedResult
=
null
let
computedResult
=
null
let
running
=
false
let
running
=
false
let
correlate
=
(
a
,
b
,
x
,
y
)
=>
{
let
correlate
Grayscale
=
(
a
,
b
,
x
,
y
)
=>
{
// score a against b, starting b from x, y
// score a against b, starting b from x, y
// a, b are float64 arrays, pixel-wise
// a, b are float64 arrays, pixel-wise
let
sumA
=
0
let
sumA
=
0
...
@@ -32,6 +32,31 @@ let correlate = (a, b, x, y) => {
...
@@ -32,6 +32,31 @@ let correlate = (a, b, x, y) => {
return
sumDot
/
Math
.
sqrt
((
sumB
*
sumB
)
*
(
sumA
*
sumA
))
return
sumDot
/
Math
.
sqrt
((
sumB
*
sumB
)
*
(
sumA
*
sumA
))
}
}
let
correlateRBGA
=
(
a
,
b
,
x
,
y
)
=>
{
let
ai
,
bi
let
sumA
=
0
let
sumB
=
0
let
sumDot
=
0
for
(
let
i
=
0
;
i
<
a
.
length
;
i
++
){
for
(
let
j
=
0
;
j
<
a
[
0
].
length
;
j
++
){
ai
=
a
[
i
][
j
]
bi
=
b
[
i
+
x
][
j
+
y
]
// have two vals,
a
[
i
][
j
]
// has [0-3] rgba
b
[
i
+
x
][
j
+
y
]
// has [0-3] rgba
// so ? per pixel, this is like:
let
pdb
=
ai
[
0
]
*
bi
[
0
]
+
ai
[
1
]
*
bi
[
1
]
+
ai
[
2
]
*
bi
[
2
]
let
pas
=
ai
[
0
]
+
ai
[
1
]
+
ai
[
2
]
let
pbs
=
bi
[
0
]
+
bi
[
1
]
+
bi
[
2
]
let
pps
=
pdb
/
Math
.
sqrt
(
pas
*
pas
*
pbs
*
pbs
)
// per pixel score,
sumA
+=
pas
sumB
+=
pbs
sumDot
+=
pdb
}
}
return
sumDot
/
Math
.
sqrt
(
sumA
*
sumA
*
sumB
*
sumB
)
}
let
delay
=
(
time
)
=>
{
let
delay
=
(
time
)
=>
{
return
new
Promise
(
resolve
=>
{
return
new
Promise
(
resolve
=>
{
setTimeout
(()
=>
{
setTimeout
(()
=>
{
...
@@ -40,7 +65,7 @@ let delay = (time) => {
...
@@ -40,7 +65,7 @@ let delay = (time) => {
})
})
}
}
let
pack
And
Grayscale
Image
=
(
imgD
)
=>
{
let
packGrayscale
=
(
imgD
)
=>
{
// make an md array shaped like[x][y]
// make an md array shaped like[x][y]
let
arr
=
[]
let
arr
=
[]
for
(
let
x
=
0
;
x
<
imgD
.
width
;
x
++
){
for
(
let
x
=
0
;
x
<
imgD
.
width
;
x
++
){
...
@@ -50,13 +75,33 @@ let packAndGrayscaleImage = (imgD) => {
...
@@ -50,13 +75,33 @@ let packAndGrayscaleImage = (imgD) => {
for
(
let
y
=
0
;
y
<
imgD
.
height
;
y
++
){
for
(
let
y
=
0
;
y
<
imgD
.
height
;
y
++
){
for
(
let
x
=
0
;
x
<
imgD
.
width
;
x
++
){
for
(
let
x
=
0
;
x
<
imgD
.
width
;
x
++
){
// grayscale all values as we load them up:
// grayscale all values as we load them up:
arr
[
x
][
y
]
=
(
imgD
.
data
[
p
]
+
imgD
.
data
[
p
+
1
]
+
imgD
.
data
[
p
+
2
]
+
imgD
.
data
[
p
+
3
])
/
4
;
arr
[
x
][
y
]
=
(
imgD
.
data
[
p
]
+
imgD
.
data
[
p
+
1
]
+
imgD
.
data
[
p
+
2
]
)
/
3
//
+ imgD.data[p + 3]) / 4;
p
+=
4
;
p
+=
4
;
}
}
}
}
return
arr
return
arr
}
}
let
packRBGA
=
(
imgD
)
=>
{
let
arr
=
[]
for
(
let
x
=
0
;
x
<
imgD
.
width
;
x
++
){
arr
.
push
([])
for
(
let
y
=
0
;
y
<
imgD
.
height
;
y
++
){
arr
[
x
][
y
]
=
new
Float64Array
(
4
)
}
}
let
p
=
0
for
(
let
y
=
0
;
y
<
imgD
.
height
;
y
++
){
for
(
let
x
=
0
;
x
<
imgD
.
width
;
x
++
){
arr
[
x
][
y
][
0
]
=
imgD
.
data
[
p
++
]
arr
[
x
][
y
][
1
]
=
imgD
.
data
[
p
++
]
arr
[
x
][
y
][
2
]
=
imgD
.
data
[
p
++
]
arr
[
x
][
y
][
3
]
=
imgD
.
data
[
p
++
]
}
}
return
arr
}
async
function
run
(
a
,
b
){
async
function
run
(
a
,
b
){
running
=
true
running
=
true
// a is img to search for, b is img to search within. both are ImageData types
// a is img to search for, b is img to search within. both are ImageData types
...
@@ -65,8 +110,8 @@ async function run(a, b){
...
@@ -65,8 +110,8 @@ async function run(a, b){
let
numruns
=
resX
*
resY
let
numruns
=
resX
*
resY
console
.
log
(
'
numruns
'
,
numruns
)
console
.
log
(
'
numruns
'
,
numruns
)
// the move now is to make an md array of these values,
// the move now is to make an md array of these values,
let
bArr
=
pack
And
Grayscale
Image
(
b
)
let
bArr
=
pack
RBGA
(
b
)
//pack
Grayscale(b)
let
aArr
=
pack
And
Grayscale
Image
(
a
)
let
aArr
=
pack
RBGA
(
a
)
//pack
Grayscale(a)
// ok, results array like[x][y]
// ok, results array like[x][y]
let
result
=
[]
let
result
=
[]
for
(
let
x
=
0
;
x
<
resX
;
x
++
){
for
(
let
x
=
0
;
x
<
resX
;
x
++
){
...
@@ -75,7 +120,7 @@ async function run(a, b){
...
@@ -75,7 +120,7 @@ async function run(a, b){
// now fill,
// now fill,
for
(
let
x
=
0
;
x
<
resX
;
x
++
){
for
(
let
x
=
0
;
x
<
resX
;
x
++
){
for
(
let
y
=
0
;
y
<
resY
;
y
++
){
for
(
let
y
=
0
;
y
<
resY
;
y
++
){
result
[
x
][
y
]
=
correlate
(
aArr
,
bArr
,
x
,
y
)
result
[
x
][
y
]
=
correlate
RBGA
(
aArr
,
bArr
,
x
,
y
)
}
}
await
delay
(
0
)
// to avoid blocking,
await
delay
(
0
)
// to avoid blocking,
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment