* Normalizes the image. * @example * ```ts * import { Jimp } from "jimp"; * * const image = await Jimp.read("test/image.png"); * * image.normalize(); * ```
(image: I)
| 279 | * ``` |
| 280 | */ |
| 281 | normalize<I extends JimpClass>(image: I) { |
| 282 | const h = histogram(image); |
| 283 | |
| 284 | // store bounds (minimum and maximum values) |
| 285 | const bounds = { |
| 286 | r: getBounds(h.r), |
| 287 | g: getBounds(h.g), |
| 288 | b: getBounds(h.b), |
| 289 | }; |
| 290 | |
| 291 | // apply value transformations |
| 292 | image.scan((_, __, idx) => { |
| 293 | const r = image.bitmap.data[idx + 0]!; |
| 294 | const g = image.bitmap.data[idx + 1]!; |
| 295 | const b = image.bitmap.data[idx + 2]!; |
| 296 | |
| 297 | image.bitmap.data[idx + 0] = normalizeValue( |
| 298 | r, |
| 299 | bounds.r[0]!, |
| 300 | bounds.r[1]!, |
| 301 | ); |
| 302 | image.bitmap.data[idx + 1] = normalizeValue( |
| 303 | g, |
| 304 | bounds.g[0]!, |
| 305 | bounds.g[1]!, |
| 306 | ); |
| 307 | image.bitmap.data[idx + 2] = normalizeValue( |
| 308 | b, |
| 309 | bounds.b[0]!, |
| 310 | bounds.b[1]!, |
| 311 | ); |
| 312 | }); |
| 313 | |
| 314 | return image; |
| 315 | }, |
| 316 | |
| 317 | /** |
| 318 | * Inverts the colors in the image. |
nothing calls this directly
no test coverage detected
searching dependent graphs…