From d5e422dadd5eafc6ef7e3ec6a8c1268365daf67a Mon Sep 17 00:00:00 2001 From: Christian Mahnke Date: Tue, 10 Sep 2024 08:00:43 +0200 Subject: [PATCH] Minor updates --- assets/js/vibrate.js | 26 ++++ content/post/haptic-feedback/index.md | 18 +-- content/post/haptic-feedback/page031-map.json | 146 +++++++++++++++++- scripts/height-map.py | 100 +++++++----- 4 files changed, 234 insertions(+), 56 deletions(-) create mode 100644 assets/js/vibrate.js diff --git a/assets/js/vibrate.js b/assets/js/vibrate.js new file mode 100644 index 0000000000..56055b8720 --- /dev/null +++ b/assets/js/vibrate.js @@ -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 + */ + +} diff --git a/content/post/haptic-feedback/index.md b/content/post/haptic-feedback/index.md index a80fe509d9..398e01b349 100644 --- a/content/post/haptic-feedback/index.md +++ b/content/post/haptic-feedback/index.md @@ -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 diff --git a/content/post/haptic-feedback/page031-map.json b/content/post/haptic-feedback/page031-map.json index 2b51a3543c..f300061807 100644 --- a/content/post/haptic-feedback/page031-map.json +++ b/content/post/haptic-feedback/page031-map.json @@ -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 + } + } + } + ] +} diff --git a/scripts/height-map.py b/scripts/height-map.py index d85b4f9f8b..99a607baf7 100644 --- a/scripts/height-map.py +++ b/scripts/height-map.py @@ -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) @@ -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'] @@ -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') @@ -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))