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)

    多层文件图片边缘分割

  • 相关阅读:
    玩家上线
    小退
    GS发包到MS
    share初始化
    3 水仙花数
    The left-hand side of an assignment must be a variable,代码中使用了中文的字符
    Mac Sublime Text 浏览器 设置快捷键 让html文件在浏览器打开
    2 质数求解
    1 斐波那契的兔子
    18 赛手的名单
  • 原文地址:https://www.cnblogs.com/ziytong/p/10705234.html
Copyright © 2011-2022 走看看