if __name__ == '__main__': #Check params are correct try: '''Get command line args''' input_dir = sys.argv[1] output_dir = sys.argv[2] except: print "USAGE: python GroundTruthMasks input_dir output_dir" exit() #Output fill colours for different types of annotations annotation2fill = { 'golgi': 'white', 'ambiguous': 'blue'} #'white'} #Get the file paths to read from annotation_files = directory_paths(input_dir) #Open all the files and read the JSON files = batch_open_deserialise(annotation_files) #For all the ground truths for file in files: polygons = file['shapes'] file['imagePath'] = fix_path(file['imagePath']) #Force the file ext. to .jpg. Sometimes it's stored wrong and needs this correction. print "opening " + file['imagePath'] image = Image.open(file['imagePath']) polygon_images = [] #For each ground truth annotation for polygon in polygons:
cascade_xml_path = sys.argv[1] test_annotation_dir = sys.argv[2] except: print "USAGE: python Accuracy cascade_xml_path test_annotation_dir" exit() try: #Open up the cascade classifier cascade = CascadeClassifier(cascade_xml_path) except: print "Error reading cascade xml" exit() #Get the file paths to read from detector_output_files = directory_paths(test_annotation_dir) #Open all the files and read the JSON annotation_files = batch_open_deserialise(detector_output_files) #For each of the hand marked test files for annotation_file in annotation_files: #Read the image corresponding to the annotation img = imread(fix_path(annotation_file['imagePath'])) print "detecting... " classifier_output = cascade.detectMultiScale(img, minNeighbors=3, minSize=(175, 175), #Constrain scale within a range around training scale maxSize=(225, 225)) #Run the detector total_detections = len(classifier_output)
'''USAGE: python RandNegPatchSample input_dir output_dir number_of_samples''' PATCH_SIZE = 200 i = 0 try: '''Get command line args''' input_dir = sys.argv[1] output_dir = sys.argv[2] samples_count = int(sys.argv[3]) except: print "USAGE: python RandNegPatchSample input_dir output_dir number_of_samples" exit() #Get the file paths to read from files = directory_paths(input_dir) for file in files: #open up the electron micrograph image image = Image.open(file) i += 1 #Loop for each sample required for j in range(samples_count): #pick a random box in the image x = randint(0, image.size[0] - PATCH_SIZE) y = randint(0, image.size[1] - PATCH_SIZE) candidate_patch_coords = (x, y, x + PATCH_SIZE, y + PATCH_SIZE) candidate_patch = box(*candidate_patch_coords)