Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cmahnke committed Sep 10, 2024
1 parent 579d509 commit d5e422d
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 56 deletions.
26 changes: 26 additions & 0 deletions assets/js/vibrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

var supportsVibrate = "vibrate" in navigator;
if (!supportsVibrate) {
return
}

function addHapticFeedback (elem, jsonUrl) {
var touchMap =fetch(jsonUrl, {
method: 'GET',
headers: {
'Accept': 'application/json',
},
})
.then(response => response.json())
.then(response => console.log(JSON.stringify(response)))
if (touchMap !== undefined) {

}

//TODO: Finish this
/* See:
https://www.chestysoft.com/imagefile/javascript/get-coordinates.asp
https://stackoverflow.com/questions/75262324/javascript-how-to-get-the-exact-touch-position-on-an-image
*/

}
18 changes: 9 additions & 9 deletions content/post/haptic-feedback/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ Diese Schritte sind konfigurierbar für jeden einzelnen Bildausschnitt, das Ziel
* Welche Kantenlänge jeder dieser Punkte haben soll - derzeit 1mm
* Wie viele Abstufungen von Intensität nützlich sind - derzeit nur 2 (An und Aus)

{{< figure src="./page031-0-cut.png" caption="Ausschnitt zur Analyse" >}}
{{< figure src="./page031-1-cut.png" caption="Ausschnitt zur Analyse" >}}

{{< figure src="./page031-0-filter_0_FIND_EDGES.png" caption="Kantenerkennung" >}}
{{< figure src="./page031-1-filter_0_FIND_EDGES.png" caption="Kantenerkennung" >}}

{{< figure src="./page031-0-filter_1_EDGE_ENHANCE.png" caption="Kantenverbesserung" >}}
{{< figure src="./page031-1-filter_1_EDGE_ENHANCE.png" caption="Kantenverbesserung" >}}

{{< figure src="./page031-0-filter_2_SMOOTH_MORE.png" caption="Weichzeichnen 1" >}}
{{< figure src="./page031-1-filter_2_SMOOTH_MORE.png" caption="Weichzeichnen 1" >}}

{{< figure src="./page031-0-filter_3_SMOOTH_MORE.png" caption="Weichzeichnen 2" >}}
{{< figure src="./page031-1-filter_3_SMOOTH_MORE.png" caption="Weichzeichnen 2" >}}

{{< figure src="./page031-0-filter_4_GRAYSCALE.png" caption="Graustufen" >}}
{{< figure src="./page031-1-filter_4_GRAYSCALE.png" caption="Graustufen" >}}

{{< figure src="./page031-0-filter_5_EQUALIZE.png" caption="Mittelwert" >}}
{{< figure src="./page031-1-filter_5_EQUALIZE.png" caption="Mittelwert" >}}

{{< figure src="./page031-0-filter_6_BINARIZE.png" caption="Binarisieren" >}}
{{< figure src="./page031-1-filter_6_BINARIZE.png" caption="Binarisieren" >}}

{{< figure src="./page031-0.png" caption="Reduktion auf eine Pixelkantenlänge von 1mm" >}}
{{< figure src="./page031-1.png" caption="Reduktion auf eine Pixelkantenlänge von 1mm" >}}

# Das Ergebnis

Expand Down
146 changes: 138 additions & 8 deletions content/post/haptic-feedback/page031-map.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,138 @@
[{
"name": "Cordsamt",
"coords": {
"position": {"x": 2304, "y": 488},
"size": {"x": 1360, "y": 864}
},
"filters": ["FIND_EDGES", "EDGE_ENHANCE", "SMOOTH_MORE", "SMOOTH_MORE", "GRAYSCALE", "EQUALIZE", {"name": "BINARIZE", "params": {"threshold": 108}}]
}]
{
"defaults": {
"filters": [
"FIND_EDGES",
"EDGE_ENHANCE",
"SMOOTH_MORE",
"SMOOTH_MORE",
"GRAYSCALE",
"EQUALIZE",
{
"name": "BINARIZE",
"params": {
"threshold": 108
}
}
]
},
"fragments": [
{
"name": "Baumwollsamt",
"coords": {
"position": {
"x": 616,
"y": 572
},
"size": {
"x": 1408,
"y": 814
}
}
},
{
"name": "Cordsamt",
"coords": {
"position": {
"x": 2304,
"y": 488
},
"size": {
"x": 1360,
"y": 864
}
},
"filters": [
"FIND_EDGES",
"EDGE_ENHANCE",
"SMOOTH_MORE",
"SMOOTH_MORE",
"GRAYSCALE",
"EQUALIZE",
{
"name": "BINARIZE",
"params": {
"threshold": 108
}
}
]
},
{
"name": "Seidensamt",
"coords": {
"position": {
"x": 627,
"y": 1914
},
"size": {
"x": 1364,
"y": 891
}
}
},
{
"name": "Spiegelsamt",
"coords": {
"position": {
"x": 2266,
"y": 1925
},
"size": {
"x": 1353,
"y": 858
}
}
},
{
"name": "Kunstseidensamt",
"coords": {
"position": {
"x": 594,
"y": 3344
},
"size": {
"x": 1375,
"y": 847
}
}
},
{
"name": "Leinenplüsch",
"coords": {
"position": {
"x": 2288,
"y": 3322
},
"size": {
"x": 1408,
"y": 869
}
}
},
{
"name": "Wirbelplüsch",
"coords": {
"position": {
"x": 561,
"y": 4686
},
"size": {
"x": 1419,
"y": 924
}
}
},
{
"name": "",
"coords": {
"position": {
"x": 2288,
"y": 4620
},
"size": {
"x": 1397,
"y": 1001
}
}
}
]
}
100 changes: 61 additions & 39 deletions scripts/height-map.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,47 @@
import argparse, pathlib, json
from termcolor import cprint

def filter(operations, image):
for j in range(len(operations)):
op = operations[j]
if (isinstance(op, str)):
name = op.upper()
elif (isinstance(op, dict)):
name = op['name'].upper()
cprint("Applying filter {}".format(name), 'yellow')
if ('params' in op):
params = op['params']
cprint("Using arguments {}".format(params), 'yellow')
if (name == 'FIND_EDGES'):
image = image.filter(ImageFilter.FIND_EDGES)
elif (name == 'EDGE_ENHANCE'):
image = image.filter(ImageFilter.EDGE_ENHANCE)
elif (name == 'EDGE_ENHANCE_MORE'):
image = image.filter(ImageFilter.EDGE_ENHANCE_MORE)
elif (name == 'SMOOTH'):
image = image.filter(ImageFilter.SMOOTH)
elif (name == 'SMOOTH_MORE'):
image = image.filter(ImageFilter.SMOOTH_MORE)
elif (name == 'GRAYSCALE'):
image = image.convert('L')
elif (name == 'INVERT'):
image = ImageOps.invert(image)
elif (name == 'EQUALIZE'):
image = ImageOps.equalize(image)
elif (name == 'BINARIZE'):
# Make sure that converted images are saved in a format that can store binary images (JPEG can't)
if ('threshold' in params):
threshold = params['threshold']
else:
threshold = 128
image = image.point(lambda x : 255 if x > threshold else 0, mode='1')
if (debug):
debugFileName = args.image.parent.joinpath(args.image.stem + "-{}-filter_{}_{}".format(i, j, name) + '.png')
cprint("Saving image {}".format(debugFileName), 'yellow')
image.save(debugFileName)
return image


parser = argparse.ArgumentParser(description='Create height map')
parser.add_argument('--image', type=pathlib.Path, help='Image to process', required=True)
parser.add_argument('--metadata', type=pathlib.Path, help='File containing metadata', required=True)
Expand All @@ -20,6 +61,8 @@
dpi = dpi[0]
pixelPerMm = dpi * 1 / 25.4
cprint("Input DPI: {}, pixel per mmm: {}".format(dpi, pixelPerMm), 'yellow')
fragments = []


if (len(args.output) == 0):
outputs = ['png']
Expand All @@ -32,7 +75,12 @@
cprint('Enabeling debug mode', 'yellow')
cprint('Requested output formats: ' + ', '.join(outputs), 'yellow')

metadata = json.load(args.metadata.open())
page = json.load(args.metadata.open())
metadata = page["fragments"]
if "defaults" in page and "filters" in page["defaults"]:
default_filters = page["defaults"]["filters"]
else:
default_filters = None
for i in range(len(metadata)):
cprint("Processing image {} from file {}".format(i, args.image), 'yellow')

Expand All @@ -46,44 +94,18 @@
debugFileName = args.image.parent.joinpath(args.image.stem + "-{}-cut".format(i) + '.png')
cprint("Saving image {}".format(debugFileName), 'yellow')
image.save(debugFileName)
operations = metadata[i]['filters']
for j in range(len(operations)):
op = operations[j]
if (isinstance(op, str)):
name = op.upper()
elif (isinstance(op, dict)):
name = op['name'].upper()
cprint("Applying filter {}".format(name), 'yellow')
if ('params' in op):
params = op['params']
cprint("Using arguments {}".format(params), 'yellow')
if (name == 'FIND_EDGES'):
image = image.filter(ImageFilter.FIND_EDGES)
elif (name == 'EDGE_ENHANCE'):
image = image.filter(ImageFilter.EDGE_ENHANCE)
elif (name == 'EDGE_ENHANCE_MORE'):
image = image.filter(ImageFilter.EDGE_ENHANCE_MORE)
elif (name == 'SMOOTH'):
image = image.filter(ImageFilter.SMOOTH)
elif (name == 'SMOOTH_MORE'):
image = image.filter(ImageFilter.SMOOTH_MORE)
elif (name == 'GRAYSCALE'):
image = image.convert('L')
elif (name == 'INVERT'):
image = ImageOps.invert(image)
elif (name == 'EQUALIZE'):
image = ImageOps.equalize(image)
elif (name == 'BINARIZE'):
# Make sure that converted images are saved in a format that can store binary images (JPEG can't)
if ('threshold' in params):
threshold = params['threshold']
else:
threshold = 128
image = image.point(lambda x : 255 if x > threshold else 0, mode='1')
if (debug):
debugFileName = args.image.parent.joinpath(args.image.stem + "-{}-filter_{}_{}".format(i, j, name) + '.png')
cprint("Saving image {}".format(debugFileName), 'yellow')
image.save(debugFileName)
if "filters" in metadata[i]:
cprint("Using fragment specific filter", 'yellow')
operations = metadata[i]['filters']
image = filter(operations, image)
applied_filters = operations
elif default_filters is not None:
cprint("Using page default filter", 'yellow')
image = filter(default_filters, image)
applied_filters = default_filters
else:
applied_filters = ""
fragments.append({"position": {"left": left, "top": top, "right": right, "bottom": bottom}, "image": args.image, "filter": applied_filters})

if (args.pixel_size != 0):
width = round(image.size[0] / (pixelPerMm * args.pixel_size))
Expand Down

0 comments on commit d5e422d

Please sign in to comment.