Skip to content

Instantly share code, notes, and snippets.

@sohiniroych
Created March 10, 2021 23:29
Show Gist options
  • Select an option

  • Save sohiniroych/bf757b580c85025b52819e0a68564e1d to your computer and use it in GitHub Desktop.

Select an option

Save sohiniroych/bf757b580c85025b52819e0a68564e1d to your computer and use it in GitHub Desktop.
Preparing 3 class data
def prepare_multi_class_GT(GT_PATH, class_names, savepath, target_size=(512,512), n_class=3):
f_names = os.listdir(GT_PATH+class_names[0])
for files in f_names:
GT_im=np.zeros(np.concatenate((target_size,n_class),axis=None)) #This creates a zero array of size (512,512,3)
FG=np.zeros(target_size)
for idx,cn in enumerate(class_names):
lab=io.imread(GT_PATH+cn+files, as_gray=True)
lab = trans.resize(lab,target_size)
if(np.max(lab)>1):
lab=lab/255
lab[lab>=0.1]=1 #threshold at 0.1. Change this value based on your requirement
lab[lab<0.1]=0
if (idx<2): #Red Lesions
GT_im[:,:,0]=((GT_im[:,:,0]+lab)>0).astype(int)
FG=((FG+lab)>0).astype(int)
else:#Bright Lesions
GT_im[:,:,1]=((GT_im[:,:,1]+lab-FG)>0).astype(int)
io.imsave(savepath+files,GT_im)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment