- Scikit-Image 教程
- Scikit-Image - 简介
- Scikit-Image - 图像处理
- Scikit-Image - NumPy图像
- Scikit-Image - 图像数据类型
- Scikit-Image - 使用插件
- Scikit-Image - 图像处理
- Scikit-Image - 读取图像
- Scikit-Image - 写入图像
- Scikit-Image - 显示图像
- Scikit-Image - 图像集合
- Scikit-Image - 图像栈
- Scikit-Image - 多张图像
- Scikit-Image - 数据可视化
- Scikit-Image - 使用Matplotlib
- Scikit-Image - 使用Plotly
- Scikit-Image - 使用Mayavi
- Scikit-Image - 使用Napari
Scikit-Image - 图像栈
总的来说,栈是指一组协同工作以实现应用程序特定功能的独立组件的集合。
另一方面,图像栈组合了一组共享共同参考的图像。虽然栈中的图像在质量或内容方面可能有所不同,但它们被组织在一起以便于高效处理和分析。图像栈被分组在一起用于分析或处理目的,从而实现高效的批量操作。
在scikit-image库中,**io模块**提供了专门用于处理图像栈的`push()`和`pop()`函数。
Io.pop() 和 io.push() 函数
**pop()**函数用于从共享图像栈中移除一张图像。它将从栈中弹出的图像作为NumPy ndarray返回。
而**push(img)**函数用于向共享图像栈中添加特定图像。它接受**NumPy ndarray**(图像数组)作为输入。
示例
以下示例演示了如何使用**io.push()**将图像推入共享栈,以及如何使用**io.pop()**从栈中检索图像。它还将显示尝试从空栈中弹出图像将引发名为**IndexError**的错误。
import skimage.io as io
import numpy as np
# Generate images with random numbers
image1 = np.random.rand(2, 2)
image2 = np.random.rand(1, 3)
# Push all image onto the shared stack one by one
io.push(image1)
io.push(image2)
# Pop an image from the stack
popped_image_array1 = io.pop()
# Display the popped image array
print("The array of popped image",popped_image_array1)
# Pop another image from the stack
popped_image_array2 = io.pop()
# Display the popped image array
print("The array of popped image",popped_image_array2)
popped_image_array3 = io.pop() # Output IndexError
popped_image_array3
输出
The array of popped image [[0.58981037 0.04246133 0.78413075]]
The array of popped image [[0.47972125 0.55525751]
[0.02514485 0.15683907]]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_792\2226447525.py in < module >
23
24 # will rice an IndexError
---> 25 popped_image_array3 = io.pop()
26 popped_image_array3
~\anaconda3\lib\site-packages\skimage\io\_image_stack.py in pop()
33
34 """
---> 35 return image_stack.pop()
IndexError: pop from empty list
上述示例的最后两行将引发IndexError。这是因为只有两张图像使用io.push()推入共享栈,但是第三次调用io.pop()尝试从栈中弹出图像,由于栈在第一次弹出后为空,导致IndexError。
广告