Published
Edited
Aug 4, 2021
2 forks
7 stars
Hello, PGLiteINSEE ParquetHello, apcachDruidJS workerHello, OrbitWord Tour: 40k words and their friendsHello, spectral.jsHello, petite-vueHello, @thi.ng/grid-iteratorsHello, thumbhashHello, SwissGLHello, QOI (and glitches)Hello, orbHello, cosmographHello, TabulatorUsing d3.blur with PlotMath.cbrtHello debounceColorcetHello, gliiHello, Open Meteo
Hello, PyWavelets
Hello, typesenseHello, libgifHello, kmeans-engineHappy anniversary, Project Gutenberg!Hello, fflateHello, ArchieML!Hello, d3-bboxCollideHello, jsgeoda!Hello, EDTF!Hello, protovis!Hello, placekeyHello, fuse.jsHello, Reorder.jsHello, shadow DOMjszipHello, procedural-glHello, qhullHello, genetic-jsDruidJSHello, Tippy.jsHello, paintWorkletBig πHello, AutoencoderHello, Shakespearean UUIDsHello, ccwt.jsHello, constrainautorHello, talismanHello, polygon-offsetHello p-queueHello async-poolHello rollup-plugin-asciiHello, algebra.jsHello, pixi.jsHello, d3-renderHello zip/unzipCumulative Wikipedia DonationsHTML <details>regl textureHello, npyjsHello protobufHello, pencil touchHello, LOESSHello html2canvaslegra mapscolor2cssHello, ecsy2D point distributionsHello, delatinThe gpu.js loopDijkstra’s shortest-path treeHello nojacko/Dijkstras-jsHello, tcort/dijkstrajsHello, lambdabaa/dijkstraHello, gpu.js v2Hello jsqrHello qrcodeHello SharedArrayBufferHello GamePad APIHello vtk.jsHello nd4jsHello BiofabricTravelling with a self-organizing mapHello glitchHello UMAP-jsHello pandemoniumHello iocaneHello JSON-editorHello d3-griddingHello mljs/knnWorkerHello lalolibImage to GPU.jsImage to blink.jsTissot's indicatrixVega projectionsHello WebCLGLUsing d3-inertia with observableVideo contouring 3ngraph: pagerank, louvain…Union-FindPerceptron (simple statistics)mljsHello h3-jsEmoji FlagsHello, poisson-disk-sampling
Also listed in…
Image
Algorithms
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
image = FileAttachment("camera.png").image()
Insert cell
coeffs = py`
# Wavelet transform of image
import numpy as np
import pywt
import pywt.data

pywt.dwt2(${pixels}, ${waveletType})
`
Insert cell
wvTypes = py`
import pywt
[pywt.wavelist(family) for family in pywt.families()]
`
Insert cell
display = (coeffs) => py`
########################################### patch matplotlib for Observable #######
## taken from "@gnestor/pyodide-demo"
from matplotlib import pyplot as plt
import types
import io
import base64
from js import document
def _show(self):
buf = io.BytesIO()
self.savefig(buf, format='png')
buf.seek(0)
img_str = 'data:image/png;base64,' + base64.b64encode(buf.read()).decode('UTF-8')
el = document.createElement('img')
el.src = img_str
return el
plt._show = types.MethodType(plt.show, plt)
plt.show = types.MethodType(_show, plt)
####################################################################################

LL, (LH, HL, HH) = ${coeffs}

# Plot approximation and details
titles = ['Approximation', ' Horizontal detail',
'Vertical detail', 'Diagonal detail']
fig = plt.figure(figsize=(12, 3))
for i, a in enumerate([LL, LH, HL, HH]):
ax = fig.add_subplot(1, 4, i + 1)
ax.imshow(a, interpolation="nearest", cmap=plt.cm.gray)
ax.set_title(titles[i], fontsize=10)
ax.set_xticks([])
ax.set_yticks([])

fig.tight_layout()

plt.show()
`
Insert cell
import { py, pyodide } from "@gnestor/pyodide"
Insert cell
pixels = {
const w = image.naturalWidth;
const h = image.naturalHeight;
const context = DOM.context2d(w, h, 1);
context.drawImage(image, 0, 0);
const { data } = context.getImageData(0, 0, w, h);
const pixels = [];
for (let y = 0; y < h; y++)
pixels.push(
Uint8Array.from({ length: w }, (_, x) =>
gray(data.slice(4 * (x + w * y), 4 * (x + w * y + 1)))
)
);

return pixels;
}
Insert cell
// Adobe Photoshop RGB (1998); proper grayscale conversion
function gray([r, g, b]) {
const gamma = 2.2;
return (
(r ** gamma * 0.2973 + g ** gamma * 0.6274 + b ** gamma * 0.0753) **
(1 / gamma)
);
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more