zoukankan      html  css  js  c++  java
  • 二值图片轮廓提取

    # -*- coding: UTF-8 -*-
    
    import cv2
    import numpy as np
    import os
    
    
    reagents = ['MaskVIA1', 'MaskVIA3', 'MaskVILI']
    if __name__ == '__main__':
    
        path = 'F:/project/Cancer/dataset/Cervical_Data/Cut_Data/CANCER/3/'
    
        for file_name in os.listdir(path):
    
    
            if not os.path.isdir(path+'/'+file_name):
    
    
                print(file_name)
                image = cv2.imread(path + '/' + file_name)
                gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
                gray_image = cv2.Canny(gray_image, 100, 200)
                gray_image = cv2.morphologyEx(gray_image, cv2.MORPH_DILATE, np.ones((5, 5), np.uint8))
    
                gray_image = 255 - gray_image
    
                cv2.imwrite(path + 'new_label/' + file_name.split('.')[0] + '.' + file_name.split('.')[1], gray_image)
    
                '''
                cv2.imshow(file_name, gray_image)
                cv2.waitKey(0)
                cv2.destroyWindow(file_name)
                '''
    
        print('all_finished')

    单个文件夹内部图片提取

    # -*- coding: UTF-8 -*-
    
    import cv2
    import numpy as np
    import os
    
    
    class_names = ['NORMAL', 'CIN1', 'CIN2', 'CIN3', 'CANCER']
    reagents = ['MaskVIA1', 'MaskVIA3', 'MaskVILI']
    
    if __name__ == '__main__':
    
        path = 'F:/project/Cancer/dataset/Cervical_Data/Cut_Data'
        path1 = 'F:/project/Cancer/dataset/Cervical_Data/Labels'
    
        for class_name in class_names:
            src_path = path + '/' + class_name
            src_path1 = path1 + '/' + class_name
            for patient_code in os.listdir(src_path):
                src_patient_dir = src_path + '/' + patient_code
                print(src_patient_dir)
                tar_patient_dir = src_path1 + '/' + patient_code
                print(tar_patient_dir)
                file_names = [res for res in os.listdir(src_patient_dir) if   (res.startswith('Mask') and res.endswith('.jpg'))]
                os.makedirs(tar_patient_dir)
                for file_name in file_names:
                    print(file_name)
                    image = cv2.imread(src_patient_dir + '/' + file_name)
                    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
                    gray_image = cv2.Canny(gray_image, 100, 200)
                    gray_image = cv2.morphologyEx(gray_image, cv2.MORPH_DILATE, np.ones((10, 10), np.uint8))
    
                    gray_image = 255 - gray_image
    
                    cv2.imwrite(tar_patient_dir  +'/' + file_name, gray_image)

    多层文件图片边缘分割

  • 相关阅读:
    计蒜客 跳跃游戏2
    计蒜客 跳跃游戏
    2018 计蒜之道-初赛 第一场 A-百度无人车
    poj 3625 (最小生成树算法)
    poj 3623(贪心)
    poj2386(dfs搜索水题)
    poj 2761 主席树的应用(查询区间第k小值)
    POJ 2456 编程技巧之------二分查找思想的巧妙应用
    POJ 1995(有关快速幂运算的一道水题)
    1441:【例题2】生日蛋糕
  • 原文地址:https://www.cnblogs.com/ziytong/p/10705234.html
Copyright © 2011-2022 走看看