image_modifier.slice_image
Module Contents
Functions
|
Slices an image into smaller sections (slices) based on specified horizontal and vertical divisions. |
|
Visualizes slices of an image in a grid format using matplotlib and returns the slices. |
- image_modifier.slice_image.image_break_into_slices(image, horizontal_slices, vertical_slices)[source]
Slices an image into smaller sections (slices) based on specified horizontal and vertical divisions.
This function segments an image array into smaller rectangular portions. The image is divided into a grid defined by the number of horizontal and vertical slices. Each portion of the grid corresponds to a slice.
- Parameters:
image (numpy.ndarray) – The image to be divided, represented as a 3D RGB array.
horizontal_slices (int) – The number of slices along the horizontal axis.
vertical_slices (int) – The number of slices along the vertical axis.
- Returns:
A list where each sublist contains numpy arrays representing horizontal slices. The overall structure represents the entire sliced image.
- Return type:
list[list[numpy.ndarray]]
Example:
Given a numpy array representing an 8x8 pixel image:
>>> slices = image_break_into_slices(image, 2, 2)
This will return a list with 4 sublists (2x2 grid), each sublist containing a numpy array for a 4x4 pixel slice.
- image_modifier.slice_image.slice_image(image, horizontal_slices=2, vertical_slices=2, display_images=True)[source]
Visualizes slices of an image in a grid format using matplotlib and returns the slices.
This function first uses image_break_into_slices to divide the image into smaller sections and then displays these slices in a grid layout using matplotlib. Each slice is shown in a subplot with its position in the grid.
- Parameters:
image (numpy.ndarray) – The image to be sliced and displayed.
horizontal_slices (int, optional) – The number of horizontal divisions for slicing. Default is 2.
vertical_slices (int, optional) – The number of vertical divisions for slicing. Default is 2.
display_images (bool) – If True, display the images using matplotlib. Default is True.
- Returns:
A list of numpy arrays, each representing a slice of the original image.
- Return type:
list[list[numpy.ndarray]]
The function assumes the slices form a rectangular grid and directly displays the plot using matplotlib.