Segmentation in Medical Images using pixel coordinates as labels

Thank you Matthieu and everybody who showed interest in helping out with this issue. But I think I found a solution. Please find a small snippet of code which can be used when we have label data in this pixel coordinate format.

for k in range(len(image_paths)):  #going through the folder where I have all the Images stored

    image = plt.imread(path+image_paths[k]+".png") #reading the image
    print(image_paths[k]+".png")

    image=rgb2hed(image) #As the images are H&E - Hamotoxylin and Eosin stained images, we change it to this format (I also discovered about this while browsing some of this content on skimage) something new ;P

    scipy.misc.imsave(os.path.join(path_train, image_paths[k]+".png"), image)
    X_train.append(image[:,:,0:3])

    height=image.shape[0]
    width=image.shape[1]
    patch = np.full((height,width),255)

   #This is the part which helped me take those pixel values provided and create a patch like structure in the image. 
    f = open(path+image_paths[k]+".csv", "r")

    for line in f:
       lines=line.split()
       pixels=lines[0].split(",")

       for i in range(0,len(pixels),2): #putting 2, as 2 values denote x and y coordinate(lucky guess)
             patch[int(pixels[i+1])][int(pixels[i])]=0
        
    scipy.misc.imsave(os.path.join(path_label, image_paths[k]+".png"), patch)  #saved it as a patch and it worked 

Apologies if If the information provided in the first place was not that suffecient.

Regards,
Sahil

1 Like