MCPcopy
hub / github.com/huggingface/transformers.js / split

Method split

packages/transformers/src/utils/image.js:700–718  ·  view source on GitHub ↗

* Split this image into individual bands. This method returns an array of individual image bands from an image. * For example, splitting an "RGB" image creates three new images each containing a copy of one of the original bands (red, green, blue). * * Inspired by PIL's `Image.split()

()

Source from the content-addressed store, hash-verified

698 * @returns {RawImage[]} An array containing bands.
699 */
700 split() {
701 const { data, width, height, channels } = this;
702
703 /** @type {typeof Uint8Array | typeof Uint8ClampedArray} */
704 const data_type = /** @type {any} */ (data.constructor);
705 const per_channel_length = data.length / channels;
706
707 // Pre-allocate buffers for each channel
708 const split_data = Array.from({ length: channels }, () => new data_type(per_channel_length));
709
710 // Write pixel data
711 for (let i = 0; i < per_channel_length; ++i) {
712 const data_offset = channels * i;
713 for (let j = 0; j < channels; ++j) {
714 split_data[j][i] = data[data_offset + j];
715 }
716 }
717 return split_data.map((data) => new RawImage(data, width, height, 1));
718 }
719
720 /**
721 * Helper method to update the image data.

Callers 12

pipelineFunction · 0.80
saveMethod · 0.80
updateContentTypeMethod · 0.80
loadAndCacheFileFunction · 0.80
_callMethod · 0.80
_callMethod · 0.80
_callMethod · 0.80
_encode_textMethod · 0.80
_callMethod · 0.80
_callMethod · 0.80
dev.mjsFile · 0.80
utils.test.jsFile · 0.80

Calls 1

mapMethod · 0.80

Tested by

no test coverage detected