Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
covid19classification/dataset_man.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
96 lines (67 sloc)
2.6 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from turtle import pos | |
import numpy as np | |
import pandas as pd | |
import os | |
import os.path | |
import shutil | |
from pathlib import Path | |
import glob | |
folder1 = 'main_dataset' #Read the label | |
metadata = pd.read_csv(os.path.join(folder1, 'metadata.csv')) #metadata.csv contains the dataset information | |
labels = pd.read_csv(r"C:\Users\parib\Desktop\COVID-19-PROJ\main_dataset\label.csv ", names=['label','condition']) #condition | |
true_label = labels[labels['condition'] == 'TRUE'] #covid pos | |
false_label = labels[labels['condition']== 'FALSE'] #covid neg | |
positive_labels = true_label.label | |
negative_labels = false_label.label | |
positive_list = [] | |
negative_list = [] | |
for i in positive_labels: #adding each positive and negative to their dedicated folder | |
positive_list.append(i) | |
for i in negative_labels: | |
negative_list.append(i) | |
label = labels['label'] #get the label, subject ID and file location | |
#condition = labels['condition'] | |
subjectid = metadata['Subject ID'] #this is like the primary tag to find each img | |
filelocation = metadata['File Location'] #address of each img | |
filelocation_corrected = [] | |
for i in filelocation: #address modification to capture img | |
address = (i[17:]) | |
replace = address.replace('/','\\') | |
filelocation_corrected.append(replace) | |
pos_dest = "Positive" | |
source = "covidimagesoutputPNGonly" | |
files = os.listdir(source) | |
src = "covidimagesoutputPNGonly" | |
dest = "Negative" | |
def assign_category(): #moving between folders | |
for each in negative_list: | |
try: | |
shutil.copytree(src + "//" + each, dest + "//" + each) | |
except FileNotFoundError: | |
print ("File: ", each, "not found") | |
positive_folders = "Positive" | |
Negative_folders = "Negative" | |
def pos_png_only(): #seperating out the positive and negative | |
files = glob.glob("./Positive/**/*.PNG", recursive = True) | |
return files | |
def neg_png_only(): | |
files = glob.glob("./Negative/**/*.PNG", recursive = True) | |
return files | |
pos_pics_destination = "Positivepics" | |
neg_pics_destination = "Negativepics" | |
if __name__ == "__main__": | |
pos = pos_png_only() | |
neg = neg_png_only() | |
for each in pos: | |
shutil.copy(each,pos_pics_destination) #copying each category | |
print("Done copying pos pics") | |
for each in neg: | |
shutil.copy(each, neg_pics_destination) | |
print("Done copying neg pics") | |
count = 0 | |
count1 = 0 | |
for i in pos: | |
count += 1 | |
for i in neg: | |
count1 += 1 | |
print("Positive pics = ", count, "Negative pics = ", count1) #making sure we have the right amout of files | |