@imgly/background-removal-node
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -7,2 +7,22 @@ # Changelog | ||
## [1.3.0] | ||
### Added | ||
- Resources are now chunked to 4MB for better caching performance and download restart. | ||
- Seperate functions for `removeBackground`, `removeForeground`, and `segmentForeground`. Later will extract the mask only. | ||
- Config option to export 'x-alpha8' format to get receive single channel alpha mask. | ||
### Removed | ||
- Configuration options to specify if background, foreground or mask is exported. | ||
### Changed | ||
- Changed the return value type of the progress callback from undefined to void | ||
- Output is now in the original image size. Mask is upscaled and applied to the original image. | ||
## [1.2.1] | ||
@@ -14,2 +34,4 @@ | ||
- support for raw `rgba8` export formats. | ||
## [1.2.0] | ||
@@ -16,0 +38,0 @@ |
@@ -10,7 +10,30 @@ declare module '@imgly/background-removal-node/src/codecs' { | ||
export default removeBackground; | ||
export type { ImageSource, Config }; | ||
export { removeBackground }; | ||
export { removeBackground, removeForeground, segmentForeground }; | ||
export type { Config, ImageSource }; | ||
import { Config } from '@imgly/background-removal-node/src/schema'; | ||
type ImageSource = ArrayBuffer | Uint8Array | Blob | URL | string; | ||
import { ImageSource } from '@imgly/background-removal-node/src/utils'; | ||
/** | ||
* Removes the background from an image. | ||
* | ||
* @param image - The image to remove the background from. | ||
* @param configuration - Optional configuration for the background removal process. | ||
* @returns A Promise that resolves to the resulting image with the background removed. | ||
*/ | ||
function removeBackground(image: ImageSource, configuration?: Config): Promise<Blob>; | ||
/** | ||
* Removes the foreground from an image. | ||
* | ||
* @param image - The image to remove the foreground from. | ||
* @param configuration - Optional configuration for the foreground removal process. | ||
* @returns A Promise that resolves to the resulting image with the foreground removed. | ||
*/ | ||
function removeForeground(image: ImageSource, configuration?: Config): Promise<Blob>; | ||
/** | ||
* Segments the foreground of an image using a given configuration. | ||
* | ||
* @param image - The image source to segment. | ||
* @param configuration - The optional configuration for the segmentation. | ||
* @returns A Promise that resolves to the segmented foreground as a Blob. | ||
*/ | ||
function segmentForeground(image: ImageSource, configuration?: Config): Promise<Blob>; | ||
@@ -28,8 +51,7 @@ } | ||
fetchArgs?: any; | ||
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => undefined; | ||
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => void; | ||
model?: "small" | "medium" | "large"; | ||
output?: { | ||
format?: "image/png" | "image/x-rgba8" | "image/jpeg" | "image/webp"; | ||
format?: "image/png" | "image/x-alpha8" | "image/x-rgba8" | "image/jpeg" | "image/webp"; | ||
quality?: number; | ||
type?: "background" | "mask" | "foreground"; | ||
}; | ||
@@ -67,20 +89,17 @@ }; | ||
const ConfigSchema: z.ZodDefault<z.ZodObject<{ | ||
publicPath: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, string, string>; | ||
publicPath: z.ZodEffects<z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, string, string>, string, string>; | ||
debug: z.ZodDefault<z.ZodBoolean>; | ||
proxyToWorker: z.ZodDefault<z.ZodBoolean>; | ||
fetchArgs: z.ZodDefault<z.ZodAny>; | ||
progress: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodNumber, z.ZodNumber], z.ZodUnknown>, z.ZodUndefined>>; | ||
progress: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodNumber, z.ZodNumber], z.ZodUnknown>, z.ZodVoid>>; | ||
model: z.ZodDefault<z.ZodEnum<["small", "medium", "large"]>>; | ||
output: z.ZodDefault<z.ZodObject<{ | ||
format: z.ZodDefault<z.ZodEnum<["image/png", "image/jpeg", "image/webp", "image/x-rgba8"]>>; | ||
format: z.ZodDefault<z.ZodEnum<["image/png", "image/jpeg", "image/webp", "image/x-rgba8", "image/x-alpha8"]>>; | ||
quality: z.ZodDefault<z.ZodNumber>; | ||
type: z.ZodDefault<z.ZodEnum<["foreground", "background", "mask"]>>; | ||
}, "strip", z.ZodTypeAny, { | ||
format?: "image/png" | "image/x-rgba8" | "image/jpeg" | "image/webp"; | ||
format?: "image/png" | "image/x-alpha8" | "image/x-rgba8" | "image/jpeg" | "image/webp"; | ||
quality?: number; | ||
type?: "background" | "mask" | "foreground"; | ||
}, { | ||
format?: "image/png" | "image/x-rgba8" | "image/jpeg" | "image/webp"; | ||
format?: "image/png" | "image/x-alpha8" | "image/x-rgba8" | "image/jpeg" | "image/webp"; | ||
quality?: number; | ||
type?: "background" | "mask" | "foreground"; | ||
}>>; | ||
@@ -92,8 +111,7 @@ }, "strip", z.ZodTypeAny, { | ||
fetchArgs?: any; | ||
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => undefined; | ||
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => void; | ||
model?: "small" | "medium" | "large"; | ||
output?: { | ||
format?: "image/png" | "image/x-rgba8" | "image/jpeg" | "image/webp"; | ||
format?: "image/png" | "image/x-alpha8" | "image/x-rgba8" | "image/jpeg" | "image/webp"; | ||
quality?: number; | ||
type?: "background" | "mask" | "foreground"; | ||
}; | ||
@@ -105,12 +123,11 @@ }, { | ||
fetchArgs?: any; | ||
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => undefined; | ||
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => void; | ||
model?: "small" | "medium" | "large"; | ||
output?: { | ||
format?: "image/png" | "image/x-rgba8" | "image/jpeg" | "image/webp"; | ||
format?: "image/png" | "image/x-alpha8" | "image/x-rgba8" | "image/jpeg" | "image/webp"; | ||
quality?: number; | ||
type?: "background" | "mask" | "foreground"; | ||
}; | ||
}>>; | ||
type Config = z.infer<typeof ConfigSchema>; | ||
function validateConfig(config?: Config): Config; | ||
function validateConfig(configuration?: Config): Config; | ||
@@ -124,9 +141,13 @@ } | ||
declare module '@imgly/background-removal-node/src/utils' { | ||
export { imageDecode, imageEncode, tensorResize, tensorHWCtoBCHW, imageBitmapToImageData, calculateProportionalSize }; | ||
export { imageDecode, imageEncode, tensorResizeBilinear, tensorHWCtoBCHW, imageBitmapToImageData, calculateProportionalSize, imageSourceToImageData, ImageSource, convertFloat32ToUint8 }; | ||
import { Config } from '@imgly/background-removal-node/src/schema'; | ||
import { NdArray } from 'ndarray'; | ||
import { imageDecode, imageEncode } from '@imgly/background-removal-node/src/codecs'; | ||
type ImageSource = ArrayBuffer | Uint8Array | Blob | URL | string; | ||
function imageBitmapToImageData(imageBitmap: ImageBitmap): ImageData; | ||
function tensorResize(imageTensor: NdArray<Uint8Array>, newWidth: number, newHeight: number): Promise<NdArray<Uint8Array>>; | ||
function tensorResizeBilinear(imageTensor: NdArray<Uint8Array>, newWidth: number, newHeight: number): NdArray<Uint8Array>; | ||
function tensorHWCtoBCHW(imageTensor: NdArray<Uint32Array>, mean?: number[], std?: number[]): NdArray<Float32Array>; | ||
function calculateProportionalSize(originalWidth: number, originalHeight: number, maxWidth: number, maxHeight: number): [number, number]; | ||
function imageSourceToImageData(image: ImageSource, _: Config): Promise<NdArray<Uint8Array>>; | ||
function convertFloat32ToUint8(float32Array: NdArray<Float32Array>): NdArray<Uint8Array>; | ||
@@ -133,0 +154,0 @@ } |
{ | ||
"/models/small": { | ||
"chunks": { | ||
"7001d60734fdc112dd9c062635fb59cd401fb82a9d4213134bce4dbd655c803a": { | ||
"range": [ | ||
0, | ||
44342435 | ||
] | ||
"chunks": [ | ||
{ | ||
"hash": "b34a3e9350ad77140964b6a2e1e32cd9738acd9d01e5899b96be71901a22ef47", | ||
"offset": 0, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "8a85c22e472bed10198298a3d57480a5a90946dba88bddecf8b0bf0eafc06e70", | ||
"offset": 4194304, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "5faec25d2338ae8ca2c7bff72e954cebd40a04c5f34c4b6bb8ca6720fae40996", | ||
"offset": 8388608, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "b9861d932a549be455fc8ebd8ce5d413049515bfdd3edd55e136dbe05dd34ef5", | ||
"offset": 12582912, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "f070b4c4f512cfe8dd6936c3cb9a616f132894867d3d33304d83599eb6b55636", | ||
"offset": 16777216, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "10d02652d10fbc47bf93732ff9e8ad53eefbd3bd89ab3c1fbc15ddd740bea672", | ||
"offset": 20971520, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "014c9e0229363137e92b85ed3c6f56b1386c279cdd9af2d7f1960ed8428b5e94", | ||
"offset": 25165824, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "34dd3ad760f7e31b5e9144b8c387b8ecd6dc43116248c93c56dd7051ab525e3b", | ||
"offset": 29360128, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "e7ca5cc3e0afd65581642a05ac91eb8ea4d0deb868df94b8981c910212526476", | ||
"offset": 33554432, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "0ad4ebb86cfdd847901427181b7a7804dba93d868c3cd5f11a294acf36c9413f", | ||
"offset": 37748736, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "9582c0375aed822c5577a814766c4afc6c096f4ccd3b0d08af6a1794987206a1", | ||
"offset": 41943040, | ||
"size": 2399396 | ||
} | ||
}, | ||
], | ||
"size": 44342436, | ||
@@ -15,10 +64,114 @@ "mime": "application/octet-steam" | ||
"/models/medium": { | ||
"chunks": { | ||
"b6e8497ba978a6f5fbb647e419d2696cd80df5a23cb6a8ea532021911bd76acb": { | ||
"range": [ | ||
0, | ||
88188478 | ||
] | ||
"chunks": [ | ||
{ | ||
"hash": "fe1b9f06af9d2147016884f4eb683d4dc540244a7453c3b742ae527725df2eec", | ||
"offset": 0, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "724543b36c7b5eddfbd7f55cb5a7c1676b2089c277611850c257efa42212d8a2", | ||
"offset": 4194304, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "f9290547b2e34555536647c1e2ca456348170eef1aee05d8fd522f5a051f260c", | ||
"offset": 8388608, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "897d4d8a3f9f8c07f439300a5d81c8be4b0fcecf19ca6d77929b1750fedd8306", | ||
"offset": 12582912, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "cbcda0a0c830ba51928e7935d9d3cfe1c4dc258bf117f2c76d047113ab8f9f8c", | ||
"offset": 16777216, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "4c44c8b64af9f044623ceace7cc55e0bc348394f7ff63629d46118c0a03c9c54", | ||
"offset": 20971520, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "8b2e3d773d7084c5cfac1c04d69d3586e4b8914a840d2b582dfde4940d698957", | ||
"offset": 25165824, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "024e3d8beaf517d25496b73e36b0e0498110652753273e0dd8b591ad7c1c9e2f", | ||
"offset": 29360128, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "1b8eaad4cd019b76e7eba964a38711a0bdeafbd10b6208c1107403a64dbd902a", | ||
"offset": 33554432, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "0c8c5c24237304482ccc70a50008b73c8ef53e4656068da32b635607cca0c8c9", | ||
"offset": 37748736, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "a5b8c519c832bc46b2ae5a9887fac1e3d5cc76a04846d8c3544875c7f2b40960", | ||
"offset": 41943040, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "7b1dd767c5c1c0156b8d13bb34d4c1d11e014723b10cddc25c93e89a28e7cd96", | ||
"offset": 46137344, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "3f5638267419916c9d4d906ff25f721d3d2e034851ea01566f0d2d6f943550b8", | ||
"offset": 50331648, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "9927e74b3a0638d4cf5701e78e66d77476a4ba68c75831f1c8ea9117ec7f8809", | ||
"offset": 54525952, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "3315eb3c14ca3ff5c03c80fac58f486a14264dd0bb9c168c096f2bd2531ba438", | ||
"offset": 58720256, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "230f667e0332dc09ef08aacbf1992c40ce112192f95dfc14231a3ef515f9a2c7", | ||
"offset": 62914560, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "e01a157b677e0e17815cd738dcda7e6daa268898d006b52b5d3604c439e6c96e", | ||
"offset": 67108864, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "529f1df7d027b0315090ba15d42ef32998cac2efd6783c62f6b11cedf4c548f3", | ||
"offset": 71303168, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "6cfd013f552a05e9fc81156e6d6de593668e0247a3970feae22e285c16d13e62", | ||
"offset": 75497472, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "3f31511c3c16a29cf81b32379f51ead2bd082677b48b1dcc11a66beeb37cc729", | ||
"offset": 79691776, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "01f6efcc8a01c727d99073ceede8e64c654fa3c4612b006e69e22dc663236943", | ||
"offset": 83886080, | ||
"size": 4194304 | ||
}, | ||
{ | ||
"hash": "145d8355f50b7847de5d04815124790867fe1752a0013bdf6ce28882b5e0a2fc", | ||
"offset": 88080384, | ||
"size": 108095 | ||
} | ||
}, | ||
], | ||
"size": 88188479, | ||
@@ -25,0 +178,0 @@ "mime": "application/octet-steam" |
{ | ||
"name": "@imgly/background-removal-node", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Background Removal in NodeJS", | ||
@@ -51,4 +51,4 @@ "keywords": [ | ||
"changelog:generate": "node ../../scripts/changelog/generate.mjs", | ||
"build": "npm run clean && npm run resources && node scripts/build.mjs", | ||
"watch": "npm run clean && npm run resources && node scripts/watch.mjs", | ||
"build": "npm run clean && npm run resources && npm run changelog:generate && node scripts/build.mjs", | ||
"watch": "npm run clean && npm run resources && npm run changelog:generate && node scripts/watch.mjs", | ||
"publish": "npm run build && npm publish --access public", | ||
@@ -81,2 +81,2 @@ "lint": "npx prettier --write ." | ||
} | ||
} | ||
} |
@@ -61,3 +61,3 @@ # Background Removal in NodeJs | ||
type Config = { | ||
publicPath: string; // The public path used for model a | ||
publicPath: string; // The public path used for model and wasm files. Default: '`file://${path.resolve(`node_modules/${pkg.name}/dist/`)}/`. | ||
debug: bool; // enable or disable useful console.log outputs | ||
@@ -64,0 +64,0 @@ model: 'small' | 'medium'; // The model to use. (Default "medium") |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132650746
42
1270