简体   繁体   English

从特定目录读取多个图像,使用 python 和 opencv 将它们保存在另一个目录中

[英]Read multiple images from specific directory, prepossessed and save them another directory using python and opencv

I'm a beginner in Python and OpenCV.我是 Python 和 OpenCV 的初学者。 I want to read multiple images from a specific directory and preprocess them using CLAHE(Contrast Limited Adaptive histogram equalization) and finally save them (Preprocessed images) to another directory.我想从特定目录读取多个图像并使用 CLAHE(对比度受限自适应直方图均衡化)对它们进行预处理,最后将它们(预处理图像)保存到另一个目录。 I tried but it will work on a single image.我试过了,但它可以在单个图像上工作。 How do I fix it?我如何解决它? Here is my code below-下面是我的代码-

import numpy as np
import cv2
import glob

img = cv2.imread('00000001_000.png',0)

#create a CLAHE object (Arguments are optional).
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(20,20))
cl1 = clahe.apply(img)
cv2.imwrite('clahe_21.jpg',cl1)

Try having a list of path to all the images and iterate over them:尝试列出所有图像的路径并对其进行迭代:

all_img = glob.glob('.')
other_dir = 'new_path'
for img_id, img_path in enumerate(all_img):
    img = cv2.imread(img_path,0)

    #create a CLAHE object (Arguments are optional).
    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(20,20))
    cl1 = clahe.apply(img)
    cv2.imwrite(f'{other_dir}/clahe_21_{img_id}.jpg',cl1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Python和OpenCV从目录中读取图像? - How to read images from a directory with Python and OpenCV? 使用Python和OpenCV处理目录中的图像 - Processing Images from a directory using Python and OpenCV 如何使用 OpenCV VideoWriter 将视频保存到特定目录——python - How to save a video using OpenCV VideoWriter to a specific directory -- python 从目录中读取多个图像并将其转换为.csv文件 - Read multiple images from a directory and turn them into .csv files 如何使用 OpenCV 和 numpy 从 Drive 目录读取和显示图像? - How to read and display images from a Drive directory using OpenCV and numpy? Python脚本读取一个目录中的多个excel文件并将它们转换为另一个目录中的.csv文件 - Python script to read multiple excel files in one directory and convert them to .csv files in another directory 如何从一个目录中读取多个文件并在 python 中读取 append 它们? - How to read multiple files from a directory and append them in python? 使用 glob (Python) 读取多个图像并将它们保存在 csv 中 - Read multiple images using glob (Python) and save them in csv 如何使用 OpenCV 读取图像目录 - How to read in a directory of images with OpenCV 如何在 python 中使用 selenium 从网站上抓取多个图像并将它们保存在特定文件夹中? - How do I scrape multiple images from a website and save them on a specific folder using selenium in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM