Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Remove unused anti-aliasing code (since CLIP now uses ONNX)

Manav Rathi3dcf5fa86067
diff --git a/web/packages/new/photos/services/ml/face.ts b/web/packages/new/photos/services/ml/face.ts
index 0de4c6c6b4..1e7716f9fc 100644
--- a/web/packages/new/photos/services/ml/face.ts
+++ b/web/packages/new/photos/services/ml/face.ts
@@ -397,7 +397,6 @@ const convertToYOLOInputFloat32ChannelsFirst = (imageData: ImageData) => {
pixelData,
width,
height,
- false,
);
yoloInput[pi] = r / 255.0;
yoloInput[pi + channelOffsetGreen] = g / 255.0;
diff --git a/web/packages/new/photos/services/ml/image.ts b/web/packages/new/photos/services/ml/image.ts
index 14733b6604..f8d6f009b3 100644
--- a/web/packages/new/photos/services/ml/image.ts
+++ b/web/packages/new/photos/services/ml/image.ts
@@ -7,7 +7,7 @@ import { clamp } from "./math";
/**
* Returns the pixel value (RGB) at the given coordinates ({@link fx},
- * {@link fy}) using bilinear interpolation (optionally anti-aliased).
+ * {@link fy}) using bilinear interpolation.
*/
export function pixelRGBBilinear(
fx: number,
@@ -15,7 +15,6 @@ export function pixelRGBBilinear(
imageData: Uint8ClampedArray,
imageWidth: number,
imageHeight: number,
- antialias: boolean,
) {
// Clamp to image boundaries.
fx = clamp(fx, 0, imageWidth - 1);
@@ -32,11 +31,10 @@ export function pixelRGBBilinear(
const dy1 = 1.0 - dy;
// Get the original pixels.
- const getPixelRGBA = antialias ? pixelRGBABlurred : pixelRGBA;
- const pixel1 = getPixelRGBA(imageData, imageWidth, imageHeight, x0, y0);
- const pixel2 = getPixelRGBA(imageData, imageWidth, imageHeight, x1, y0);
- const pixel3 = getPixelRGBA(imageData, imageWidth, imageHeight, x0, y1);
- const pixel4 = getPixelRGBA(imageData, imageWidth, imageHeight, x1, y1);
+ const pixel1 = pixelRGBA(imageData, imageWidth, imageHeight, x0, y0);
+ const pixel2 = pixelRGBA(imageData, imageWidth, imageHeight, x1, y0);
+ const pixel3 = pixelRGBA(imageData, imageWidth, imageHeight, x0, y1);
+ const pixel4 = pixelRGBA(imageData, imageWidth, imageHeight, x1, y1);
const bilinear = (val1: number, val2: number, val3: number, val4: number) =>
Math.round(
@@ -73,32 +71,6 @@ const pixelRGBA = (
};
};
-const pixelRGBABlurred = (
- imageData: Uint8ClampedArray,
- width: number,
- height: number,
- x: number,
- y: number,
-) => {
- let r = 0,
- g = 0,
- b = 0;
- for (let ky = 0; ky < gaussianKernelSize; ky++) {
- for (let kx = 0; kx < gaussianKernelSize; kx++) {
- const px = x - gaussianKernelRadius + kx;
- const py = y - gaussianKernelRadius + ky;
-
- const pixelRgbTuple = pixelRGBA(imageData, width, height, px, py);
- const weight = gaussianKernel[ky]![kx]!;
-
- r += pixelRgbTuple.r * weight;
- g += pixelRgbTuple.g * weight;
- b += pixelRgbTuple.b * weight;
- }
- }
- return { r: Math.round(r), g: Math.round(g), b: Math.round(b), a: 255 };
-};
-
/**
* Returns the pixel value (RGB) at the given coordinates ({@link fx},
* {@link fy}) using bicubic interpolation.
@@ -315,42 +287,3 @@ export const grayscaleIntMatrixFromNormalized2List = (
}),
);
};
-
-const gaussianKernelSize = 5;
-const gaussianKernelRadius = Math.floor(gaussianKernelSize / 2);
-const gaussianSigma = 10.0;
-
-const create2DGaussianKernel = (size: number, sigma: number): number[][] => {
- const kernel = Array(size)
- .fill(0)
- .map(() => Array(size).fill(0) as number[]);
-
- let sum = 0.0;
- const center = Math.floor(size / 2);
-
- for (let y = 0; y < size; y++) {
- for (let x = 0; x < size; x++) {
- const dx = x - center;
- const dy = y - center;
- const g =
- (1 / (2 * Math.PI * sigma * sigma)) *
- Math.exp(-(dx * dx + dy * dy) / (2 * sigma * sigma));
- kernel[y]![x] = g;
- sum += g;
- }
- }
-
- // Normalize the kernel.
- for (let y = 0; y < size; y++) {
- for (let x = 0; x < size; x++) {
- kernel[y]![x]! /= sum;
- }
- }
-
- return kernel;
-};
-
-const gaussianKernel: number[][] = create2DGaussianKernel(
- gaussianKernelSize,
- gaussianSigma,
-);