import glob import os,sys import shutil import numpy as np import cv2 import matplotlib.pyplot as plt import os, random, shutil,cv2 labelDir = 'F:/project/Breast/InBreast/INBreast/Unet/data/Inbreast/yes/test/label/' imageDir = 'F:/project/Breast/InBreast/INBreast/Unet/data/Inbreast/yes/test/image/' labelDir1 = 'F:/project/Breast/InBreast/INBreast/Unet/data/Inbreast/no/test/label/' imageDir1 = 'F:/project/Breast/InBreast/INBreast/Unet/data/Inbreast/no/test/image/' # Statistical the distribution of positive sample data sum1 = np.zeros((256)) print(sum) if __name__ == '__main__': txtLists = os.listdir(labelDir) # 列出文件夹下所有的目录与文件 print(txtLists) # i = 0 for filename in txtLists: print(labelDir + filename) label = cv2.imread(labelDir + filename) image = cv2.imread(imageDir + filename) for i in range(112): for j in range(112): if label[i,j,0] == 0: sum1[image[i,j,0]] = sum1[image[i,j,0]] + 1 txtLists1 = os.listdir(labelDir1) for filename in txtLists1: print(labelDir1 + filename) label = cv2.imread(labelDir1 + filename) image = cv2.imread(imageDir1 + filename) for i in range(112): for j in range(112): if label[i,j,0] == 0: sum1[image[i,j,0]] = sum1[image[i,j,0]] + 1 print(sum1) np.savetxt("F:/project/Breast/InBreast/INBreast/Unet/data/Inbreast/yes/test/filename1.txt", sum1) # name = '0_'+str(i)+'_predict.png' # i =i + 2 # print(name) # shutil.copy(fileDir + filename, tarDir + name) # if filename.startswith('yes'): # filename1 = filename[4:] # print(filename1) # filename2 = os.path.join(tarDir, filename1.split('.')[0] + '_yes.png') # print(filename2) # elif filename.startswith('no'): # filename1 = filename[3:] # print(filename1) # filename2 = os.path.join(tarDir, filename1.split('.')[0] + '_no.png')#filename1 + '_no' # print(filename2) # # img = cv2.imread(fileDir + filename) # image = img[:,:,0] # cv2.imwrite(filename2,image) # name = 'yes_' + filename#'yes_0_'+ str(i) + '_predict.png' # name1 = 'no_' + filename#'yes_0_'+ str(i) + '_predict.png' # i = i + 1 # print(filename,name) # shutil.copy(fileDir + filename, tarDir + name) # shutil.copy(fileDir2 + filename, tarDir + name1) # shutil.copy(fileDir1 + filename, tarDir1 + name) # shutil.copy(fileDir22 + filename, tarDir1 + name1) # image1 = cv2.imread(fileDir + filename) # label1 = cv2.imread(fileDir1 + filename) # image2 = cv2.resize(image1,(448,448)) # label2 = cv2.resize(label1,(448,448)) # cv2.imwrite(fileDir + filename, image2) # cv2.imwrite(fileDir1 + filename,label2) # # source = fileDir + filename # # print(source) # shutil.copy(fileDir2 + filename, tarDir2 + name) # shutil.copy(fileDir3 + filename, tarDir3 + name)