Skip to content

Instantly share code, notes, and snippets.

@jcasado
Created March 21, 2019 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcasado/09ed81372158d25a0943e7e42088c9cc to your computer and use it in GitHub Desktop.
Save jcasado/09ed81372158d25a0943e7e42088c9cc to your computer and use it in GitHub Desktop.
Given two masks for the same file with matching cell IDs, find cells missing in the second mask.
import glob
import os
import pandas as pd
import numpy as np
import time
import skimage.io
pathIn = "Z:/Connor/Topacio_P2_AF/ashlar"
pathOut= "D:/julia/cell_filter/"
def compare_mask(path1, path2, out_filename):
img1 = skimage.io.imread(path1)
img2 = skimage.io.imread(path2)
uni1 = np.unique(img1)
uni2 = np.unique(img2)
diff = set(uni1) - set(uni2)
diff = np.array(list(diff)).astype('int')
np.savetxt(out_filename, diff, delimiter=',')
os.chdir(pathIn)
cytoFiles = [filename for filename in glob.iglob('C0*/**/cytoRingMask.tif', recursive=True)]
nucleiFiles = [filename for filename in glob.iglob('C0*/**/nucleiRingMask.tif', recursive=True)]
out_filenames = [i.split('\\')[0] + '_mask_diff.csv' for i in cytoFiles]
if len(cytoFiles) != len(nucleiFiles): print("Masks missing")
for i in range(len(cytoFiles)):
print(out_filenames[i],)
t = time.time()
path1 = nucleiFiles[i]
path2 = cytoFiles[i]
compare_mask(path1, path2, pathOut + out_filenames[i])
timeInterval = time.time() - t
print(i, "-", out_filenames[i], "\tElapsed time: ",timeInterval, " seconds.\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment