def standardiser(d, path): specname = d.split("/")[-2] print(specname) dest = d + "/3/maskedSamplesNormSize/" dirMaker(dest, True) d += path imgs = glob(d + "*.png") shapes = [] for i in imgs: shape = cv2.imread(i).shape shapes.append(shape) maxShape = np.max(np.array(shapes), axis=0) print(specname + " has max shape " + str(maxShape)) plate = np.zeros(maxShape).astype(np.uint8) for i in imgs: sampname = nameFromPath(i, 3) img = cv2.imread(i) if sampname.lower().find("c") > -1: pass #img = cv2.rotate(img, cv2.ROTATE_180) s = img.shape imgR = plate.copy() imgR[:s[0], :s[1], :] = img cv2.imwrite(dest + sampname + ".png", imgR)
def getFiles(s, size, dataHome): # copy the tif files from HPC print("Starting " + s) path = '/Volumes/USB/' + s + str(size) + '/tifFiles/' dirMaker(path) imgs = sorted(glob(dataHome + s + '/3/tifFiles/*.tif')) for i in imgs: print(" Copying " + nameFromPath(i)) os.system('scp -r ' + i + ' ' + path) print("Finished " + s)
def processErrors(dataHome, size, datasrc, plot): ''' Get the per feature error as a csv, save it and provide some quick stats ''' annosrc = dataHome + "landmark/" names = nameFromPath(sorted(glob(annosrc + "S*"))) # get the features and calculate the error between them featureErrors = getFeatureError(dataHome, size, datasrc, plot) # save as a csv dirMaker(dataHome + "landmark/") featureErrors.to_csv(dataHome + "landmark/" + datasrc + ".csv")
def pushFiles(s, size, dataHome): # send the featExtracted files to name = s.split("/")[-2] print("Starting " + name) dataDest = dataHome + "SpecimenSections/" + name + "/" dirMaker(dataDest) feats = s + str(size) + "/FeatureSectionsFinal/linearSect/" os.system('nohup scp -r ' + feats + '* ' + dataDest + " &") while True: dirsMade = len(os.listdir(dataDest)) dirsThere = len(os.listdir(feats)) print(name + ": " + str(dirsMade) + "/" + str(dirsThere)) time.sleep(20) if dirsMade == dirsThere: break print("Finished " + s)
import numpy as np from glob import glob import matplotlib.pyplot as plt src = '/Volumes/USB/H653A_11.3/3/' imgsrc = src + "SegmentationManual/" model = "ResNet101" model = "VGG16" segsrc = src + "Segmentations" + model + "/" imgDest = src + "SegmentationsEvals" + model + "/" masks = sorted(glob(segsrc + "*.png")) imgs = sorted(glob(imgsrc + "*anno*.png")) dirMaker(imgDest) maskToUse = getMatchingList(imgs, masks) for n, (m, i) in enumerate(zip(maskToUse, imgs)): if m is None: continue name = nameFromPath(i, 3) print(name + " Processing") img = cv2.imread(i) mask = cv2.imread(m)