suffix = "frames/x40/" save_path = "/home/fred/Projects/srt-cancer-img/pair-data/output/" # normalizers normalizer_rd = stainNorm_Reinhard.Normalizer() normalizer_mk = stainNorm_Macenko.Normalizer() normalizer_vd = vahadane.vahadane() for dirname in listdir(source_path): if 'A06' in dirname: print("Processing directory ", dirname) imgs = [f for f in listdir(join(source_path, dirname, suffix))] for img in imgs[1:]: source = stain_utils.read_image( join(source_path, dirname, suffix, img)) target = stain_utils.read_image( join(source_path, dirname.replace('A', 'H', 1), suffix, img.replace('A', 'H', 1))) print("Processing image: ", img) # load and fit target img normalizer_rd.fit(target) normalizer_mk.fit(target) Wt, Ht = normalizer_vd.stain_separate(target) # reinhard out = normalizer_rd.transform(source) out = cv.cvtColor(out, cv.COLOR_RGB2BGR) cv.imwrite(join(save_path, "reinhard", img), out)
import numpy as np import matplotlib.pyplot as plt norm = stainNorm_Macenko.normalizer( ) # normalizer() is the algorithm function for Macenko print("BENIGN") for i in range(0, 69): # since we have 69 images in benign class path = "Benign" + "/" #input path for images path_norm = "Benign_m_norm" + "/" #output path to keep the normalised output n = "t" + str(i) + ".tif" # image name fullpath = path + n # path to the input image fullpath_norm = path_norm + n # output path to the normalised image print(fullpath) print(fullpath_norm) i1 = utils.read_image(fullpath) # for reading images as arrays if (i == 0): #print(i1) norm.fit( i1 ) # for the first image we read, we need to fit the Mackenko normaliser() function in accordance with the first image so that we can normalise other images on this basis...norm.fit() actually # comes up with the values of mean and sd so that we can normalise the images. io.imsave((fullpath_norm), i1) #save the first image else: i2 = norm.transform( i1) # apply the Mackenko transformation algorithm for the image io.imsave((fullpath_norm), i2) # save the image print("IN SITU")