使用 skimage (Python) 批量处理 Tiff 文件
我正在寻找;在 Python 中打开、处理和保存多个 TIFF。
我有以下代码可以打开、处理和保存 1(一)个 TIFF,但我在处理多个文件时遇到问题:
import skimage.io
import skimage.viewer
import skimage
import skimage.io
# Read 1 image.TIF:
image = skimage.io.imread(fname=path)
image[2,1]= 1.0
# Process the file (make binary)
gray_image = skimage.color.rgb2gray(image)
# Blur the image to denoise (larger sigma = more noise removed)
blurred_image = skimage.filters.gaussian(gray_image, sigma=5)
# Adding threshold, t:
t = 0.8
binary_mask = blurred_image < t
# Save the file to another location:
skimage.io.imsave(fname=path, arr = binary_mask)
非常感谢任何帮助!
I am looking to; open, process and save multiple TIFFs in Python.
I have the following code to open, process and save 1 (one) TIFF, but I have trouble with multiple files:
import skimage.io
import skimage.viewer
import skimage
import skimage.io
# Read 1 image.TIF:
image = skimage.io.imread(fname=path)
image[2,1]= 1.0
# Process the file (make binary)
gray_image = skimage.color.rgb2gray(image)
# Blur the image to denoise (larger sigma = more noise removed)
blurred_image = skimage.filters.gaussian(gray_image, sigma=5)
# Adding threshold, t:
t = 0.8
binary_mask = blurred_image < t
# Save the file to another location:
skimage.io.imsave(fname=path, arr = binary_mask)
Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是一种可能有所帮助的多处理方法:
使用 glob 识别与 *.tif 模式匹配的所有文件,然后利用 ProcessPoolExecutor 的 map 函数在其自己的进程中处理每个文件。由于处理主要是 CPU 密集型的,因此多处理可能是最适合这种情况的方法
Here's a multiprocessing approach that may help:
Use glob to identify all the files matching the *.tif pattern then utilise the ProcessPoolExecutor's map function to process each file in its own process. As the processing is mainly CPU intensive, multiprocessing is likely to be the best fit for this
是否有必要并行化?您正在执行的处理量并不大。如果您不需要并行处理,您可以在图像上运行 for 循环
Is it necessary that this be parallelized? It's not a huge bit of processing that you are performing. If you don't need parallel processing you can just run a for loop on your images