码迷,mamicode.com
首页 > 其他好文 > 详细

二值图片轮廓提取

时间:2019-04-14 16:34:56      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:jpg   nbsp   can   提取   main   nts   轮廓提取   art   write   

# -*- 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)

多层文件图片边缘分割

 

二值图片轮廓提取

标签:jpg   nbsp   can   提取   main   nts   轮廓提取   art   write   

原文地址:https://www.cnblogs.com/ziytong/p/10705234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!