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)

    多层文件图片边缘分割

  • 相关阅读:
    八数码问题 Eight Digital Problem
    What is probabilistic programming? | 中文翻译
    Installing Moses on Ubuntu 16.04
    Python3 解析XML 层序遍历二叉树
    ORACLE之PACKAGE-包、存储过程、函数
    Java解析XMl文件之SAX和DOm方法
    关于Could not parse configuration: /hibernate.cfg.xml的问题
    hibernate入门
    linux常用命令
    基本STRUTS标签-学习笔记-Bean标签
  • 原文地址:https://www.cnblogs.com/ziytong/p/10705234.html
Copyright © 2011-2022 走看看