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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
squidworks
cuttlefish
Commits
a731e159
Commit
a731e159
authored
5 years ago
by
Jake Read
Browse files
Options
Downloads
Patches
Plain Diff
workers
parent
2b5f62c4
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
+144
-137
144 additions, 137 deletions
hunks/adhoc/correlate.js
with
144 additions
and
137 deletions
hunks/adhoc/correlate.js
+
144
−
137
View file @
a731e159
...
...
@@ -11,9 +11,8 @@ import {
State
}
from
'
../hunks.js
'
let
computedResult
=
null
let
running
=
false
function
worker
(){
'
use strict
'
let
correlateGrayscale
=
(
a
,
b
,
x
,
y
)
=>
{
// score a against b, starting b from x, y
// a, b are float64 arrays, pixel-wise
...
...
@@ -57,14 +56,6 @@ let correlateRBGA = (a, b, x, y) => {
return
sumDot
/
Math
.
sqrt
(
sumA
*
sumA
*
sumB
*
sumB
)
}
let
delay
=
(
time
)
=>
{
return
new
Promise
(
resolve
=>
{
setTimeout
(()
=>
{
resolve
()
},
time
)
})
}
let
packGrayscale
=
(
imgD
)
=>
{
// make an md array shaped like[x][y]
let
arr
=
[]
...
...
@@ -102,13 +93,11 @@ let packRBGA = (imgD) => {
return
arr
}
async
function
run
(
a
,
b
){
running
=
true
function
run
(
a
,
b
)
{
// a is img to search for, b is img to search within. both are ImageData types
let
resX
=
b
.
width
-
a
.
width
let
resY
=
b
.
height
-
a
.
height
let
numruns
=
resX
*
resY
console
.
log
(
'
numruns
'
,
numruns
)
// the move now is to make an md array of these values,
let
bArr
=
packRBGA
(
b
)
//packGrayscale(b)
let
aArr
=
packRBGA
(
a
)
//packGrayscale(a)
...
...
@@ -122,9 +111,7 @@ async function run(a, b){
for
(
let
y
=
0
;
y
<
resY
;
y
++
)
{
result
[
x
][
y
]
=
correlateRBGA
(
aArr
,
bArr
,
x
,
y
)
}
await
delay
(
0
)
// to avoid blocking,
}
console
.
log
(
'
run complete
'
)
// make image from the result,
let
max
=
-
Infinity
let
min
=
Infinity
...
...
@@ -139,8 +126,6 @@ async function run(a, b){
if
(
result
[
x
][
y
]
<
min
)
min
=
result
[
x
][
y
]
}
}
console
.
log
(
'
max, min
'
,
max
,
min
)
console
.
log
(
'
mp
'
,
mp
)
// now we want to unwrap this into an imagedata type,
// filling back in grayscale type
let
imdBuffer
=
new
Uint8ClampedArray
(
resX
*
resY
*
4
)
...
...
@@ -157,11 +142,17 @@ async function run(a, b){
}
}
let
imgRes
=
new
ImageData
(
imdBuffer
,
resX
,
resY
)
console
.
log
(
'
imgRes
'
,
imgRes
)
running
=
false
computedResult
=
imgRes
self
.
postMessage
(
imgRes
)
}
onmessage
=
(
evt
)
=>
{
run
(
evt
.
data
.
a
,
evt
.
data
.
b
)
}
}
let
computedResult
=
null
let
running
=
false
export
default
function
Correlate
()
{
Hunkify
(
this
)
...
...
@@ -180,7 +171,19 @@ export default function Correlate(){
this
.
dom
=
$
(
'
<div>
'
).
get
(
0
)
let
webWorker
this
.
init
=
()
=>
{
// startup the worker:
let
bleb
=
new
Blob
([
'
(
'
+
worker
.
toString
()
+
'
())
'
])
let
url
=
window
.
URL
.
createObjectURL
(
bleb
)
webWorker
=
new
Worker
(
url
)
webWorker
.
addEventListener
(
'
message
'
,
(
evt
)
=>
{
running
=
false
if
(
!
resOut
.
io
()){
resOut
.
put
(
evt
.
data
)
}
})
}
this
.
onload
=
()
=>
{
...
...
@@ -190,6 +193,12 @@ export default function Correlate(){
this
.
loop
=
()
=>
{
if
(
imgIn
.
io
()
&&
!
running
)
{
/*
imgIn.get()
running = true
console.log("POSTING")
webWorker.postMessage('msg')
*/
// ok, the image data:
let
img
=
imgIn
.
get
()
// to scale this thing, we draw it into a canvas (virtual ... not attached to page)
...
...
@@ -208,10 +217,8 @@ export default function Correlate(){
let
a
=
ctxB
.
getImageData
(
b
.
width
/
2
,
b
.
height
/
2
,
50
,
50
)
// and write that out, to debug ...
ctxA
.
putImageData
(
a
,
0
,
0
)
run
(
a
,
b
)
}
if
(
!
resOut
.
io
()
&&
computedResult
!==
null
){
resOut
.
put
(
computedResult
)
webWorker
.
postMessage
({
a
:
a
,
b
:
b
})
running
=
true
}
}
}
...
...
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