Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

251
Vistas
¿Cómo manipular una matriz multidimensional para extraer en un tamaño de matriz multidimensional específico?

Intento implementar cultivos múltiples con raw. porque, las formas tradicionales de extraer y luego guardar en el búfer son demasiado lentas. para mi tarea, una imagen toma 700ms. Quiero reducir la llamada de extracto con manipular datos sin procesar. por lo que puede acelerar 10x - 20x. mi problema en extraer marco en tamaño de bloque secuencial. digamos 16x16 desde la parte superior izquierda hasta la parte inferior derecha.

 const sharp = require('sharp'); const benchmark = () => { return new Promise((resolve) => { const currentTime = Date.now(); resolve(currentTime) }) }; const encode = async (absolutePathFile) => { const start_time = await benchmark(); const image = await sharp(absolutePathFile); const { data, info } = await image.ensureAlpha(1).raw().toBuffer({ resolveWithObject: true }); const { width, height, channels } = info; const colors = new Uint8ClampedArray(data.buffer); const pixels = []; const frame = []; const frameBlocks = []; // Convert colors to RGBA pixel for (let i=0; i < colors.length; i += channels) { const pixel = []; for (let j=i; j < i + channels; j++) { pixel.push(colors[j]) }; pixels.push(pixel) } // Convert pixels to frame let index = 0; for (let i=0; i < width; i++) { frame[i] = []; for (let j=0; j < height; j++) { frame[i][j] = pixels[index]; index += 1; } }; // Crop frame to piece of block size from left top to right bottom. const wBlockSize = 16; const hBlockSize = 16; const wBlockLength = Math.floor(width/wBlockSize); const hBlockLength = Math.floor(height/hBlockSize); for (let i=0; i < wBlockLength; i++) { for (let j=0; j < hBlockLength; j++) { const block = []; for (let k=i; k < i+wBlockSize; k++) { for (let l=j; l+hBlockSize; l++) { block.push(frame[k][l]) } }; frameBlocks.push(block) } }; const end_time = await benchmark(); const finish_time = end_time - start_time; console.log(finish_time); console.log(frameBlocks.length) }; encode(`${__dirname}/public/image.jpg`)
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda