mirror of
https://github.com/bspeice/speice.io
synced 2025-07-04 23:35:00 -04:00
Log density visualization
This commit is contained in:
@ -0,0 +1,18 @@
|
||||
export function paintLinear(width: number, histogram: Uint32Array): ImageData {
|
||||
const image = new ImageData(width, histogram.length / width);
|
||||
|
||||
let countMax = 0;
|
||||
for (let value of histogram) {
|
||||
countMax = Math.max(countMax, value);
|
||||
}
|
||||
|
||||
for (let i = 0; i < histogram.length; i++) {
|
||||
const pixelIndex = i * 4;
|
||||
image.data[pixelIndex] = 0; // red
|
||||
image.data[pixelIndex + 1] = 0; // green
|
||||
image.data[pixelIndex + 2] = 0; // blue
|
||||
image.data[pixelIndex + 3] = Number(histogram[i]) / countMax * 0xff;
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
Reference in New Issue
Block a user