From 5dc3cb83a8a81303df4481b7b84b6de78fe83af7 Mon Sep 17 00:00:00 2001 From: Conner Pribble Date: Wed, 23 Apr 2025 07:59:18 -0500 Subject: [PATCH 1/3] Create .split() term for Python image processing --- .../concepts/image/terms/split/split.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 content/pillow/concepts/image/terms/split/split.md diff --git a/content/pillow/concepts/image/terms/split/split.md b/content/pillow/concepts/image/terms/split/split.md new file mode 100644 index 00000000000..2580f81a644 --- /dev/null +++ b/content/pillow/concepts/image/terms/split/split.md @@ -0,0 +1,38 @@ +--- +Title: '.split()' +Description: 'Splits an image into individual bands.' +Subjects: + - 'Computer Science' +Tags: + - 'Python' + - 'Methods' + - 'Pillow' + - 'Images' +CatalogContent: + - 'learn-git' + - 'paths/computer-science' +--- + +The **`Image.split()`** method returns a tuple of individual image bands from an image. + +## Syntax + +```pseudo +Image.split() +``` + +Splitting an RGB image creates three new images each containing a copy of one of the original bands (red, green, blue) +- `r, g, b = Image.split()` is used to split an RGB image into separate bands +- `r, g, b, a = Image.split()` is used to split an RGBA image into separate bands + +## Example + +The following code opens an image, splits it into bands, and displays the red channel. + +```py +from PIL import Image +img = Image.open("example.jpg") +r, g, b = img.split() +r.show() +``` + From 1230721f97e2da1bbf09a648083bd5bf196ca9dc Mon Sep 17 00:00:00 2001 From: Conner Pribble Date: Wed, 23 Apr 2025 08:02:46 -0500 Subject: [PATCH 2/3] Create .split() term for Python image processing --- content/pillow/concepts/image/terms/split/split.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/pillow/concepts/image/terms/split/split.md b/content/pillow/concepts/image/terms/split/split.md index 2580f81a644..ea899cdcb15 100644 --- a/content/pillow/concepts/image/terms/split/split.md +++ b/content/pillow/concepts/image/terms/split/split.md @@ -21,7 +21,7 @@ The **`Image.split()`** method returns a tuple of individual image bands from an Image.split() ``` -Splitting an RGB image creates three new images each containing a copy of one of the original bands (red, green, blue) +Splitting an RGB image creates three new images, each containing a copy of one of the original bands (red, green, blue). - `r, g, b = Image.split()` is used to split an RGB image into separate bands - `r, g, b, a = Image.split()` is used to split an RGBA image into separate bands From 87c2f55e92f51d239dbeac442adbd120bee605f9 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Sat, 26 Apr 2025 13:43:59 +0530 Subject: [PATCH 3/3] Update split.md --- .../concepts/image/terms/split/split.md | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/content/pillow/concepts/image/terms/split/split.md b/content/pillow/concepts/image/terms/split/split.md index ea899cdcb15..0404b091fca 100644 --- a/content/pillow/concepts/image/terms/split/split.md +++ b/content/pillow/concepts/image/terms/split/split.md @@ -3,17 +3,22 @@ Title: '.split()' Description: 'Splits an image into individual bands.' Subjects: - 'Computer Science' -Tags: - - 'Python' - - 'Methods' - - 'Pillow' + - 'Data Visualization' +Tags: - 'Images' + - 'Methods' + - 'Pillow' + - 'Python' CatalogContent: - - 'learn-git' - - 'paths/computer-science' + - 'learn-python-3' + - 'paths/data-science' --- -The **`Image.split()`** method returns a tuple of individual image bands from an image. +The **`.split()`** method in the Pillow library returns a tuple containing individual bands (channels) of an image. Each band is returned as a separate grayscale image. This method is commonly used in: +- **Color manipulation:** Isolating a color channel for analysis or adjustment. +- **Image filtering:** Applying effects to individual bands. +- **Computer vision:** Preprocessing steps that require access to raw channel data. +- **Image compositing:** Combining or modifying specific color components. ## Syntax @@ -22,17 +27,22 @@ Image.split() ``` Splitting an RGB image creates three new images, each containing a copy of one of the original bands (red, green, blue). -- `r, g, b = Image.split()` is used to split an RGB image into separate bands -- `r, g, b, a = Image.split()` is used to split an RGBA image into separate bands +- For an RGB image, `.split()` returns three images corresponding to the Red, Green, and Blue bands. `r, g, b = img.split()` +- For an RGBA image, `.split()` returns four images: Red, Green, Blue, and Alpha (transparency). `r, g, b, a = img.split()` ## Example -The following code opens an image, splits it into bands, and displays the red channel. +The following code opens an image, splits it into its bands, and displays the red channel: ```py from PIL import Image + +# Open the image img = Image.open("example.jpg") + +# Split the image into bands r, g, b = img.split() + +# Show the red band r.show() ``` -