def generate_multiple_landmark_annotation_sets(retina_grader=False): graders = (UserFactory(), UserFactory(), UserFactory()) if retina_grader: add_to_graders_group(graders) landmarksets = ( LandmarkAnnotationSetFactory(grader=graders[0]), LandmarkAnnotationSetFactory(grader=graders[1]), LandmarkAnnotationSetFactory(grader=graders[0]), LandmarkAnnotationSetFactory(grader=graders[2]), ) # Create child models for landmark annotation set singlelandmarkbatches = ( SingleLandmarkAnnotationFactory.create_batch( 2, annotation_set=landmarksets[0]), SingleLandmarkAnnotationFactory.create_batch( 5, annotation_set=landmarksets[1]), [], [], ) images = [ Image.objects.filter( singlelandmarkannotation__annotation_set=landmarksets[0].id), Image.objects.filter( singlelandmarkannotation__annotation_set=landmarksets[1].id), [], [], ] # Create singlelandmarkannotations with the images of landmarkset1 for image in images[0]: singlelandmarkbatches[2].append( SingleLandmarkAnnotationFactory.create( annotation_set=landmarksets[2], image=image)) images[2].append(image) singlelandmarkbatches[3].append( SingleLandmarkAnnotationFactory.create( annotation_set=landmarksets[3], image=image)) images[3].append(image) singlelandmarkbatches[2].append( SingleLandmarkAnnotationFactory.create(annotation_set=landmarksets[2])) images[2].append(singlelandmarkbatches[2][-1].image) return MultipleLandmarkAnnotationSets( grader1=graders[0], grader2=graders[1], grader3=graders[2], landmarkset1=landmarksets[0], landmarkset1images=images[0], landmarkset2=landmarksets[1], landmarkset2images=images[1], landmarkset3=landmarksets[2], landmarkset3images=images[2], landmarkset4=landmarksets[3], landmarkset4images=images[3], )
def generate_multiple_landmark_annotation_sets(retina_grader=False): graders = (UserFactory(), UserFactory()) if retina_grader: add_to_graders_group(graders) landmarksets = ( LandmarkAnnotationSetFactory(grader=graders[0]), LandmarkAnnotationSetFactory(grader=graders[1]), LandmarkAnnotationSetFactory(grader=graders[0]), ) # Create child models for landmark annotation set singlelandmarkbatches = ( SingleLandmarkAnnotationFactory.create_batch( 2, annotation_set=landmarksets[0] ), SingleLandmarkAnnotationFactory.create_batch( 5, annotation_set=landmarksets[1] ), [], ) images = [ Image.objects.filter( singlelandmarkannotation__annotation_set=landmarksets[0].id ), Image.objects.filter( singlelandmarkannotation__annotation_set=landmarksets[1].id ), [], ] # Create singlelandmarkannotations with the images of landmarkset1 for image in images[0]: singlelandmarkbatches[2].append( SingleLandmarkAnnotationFactory.create( annotation_set=landmarksets[2], image=image ) ) images[2].append(image) singlelandmarkbatches[2].append( SingleLandmarkAnnotationFactory.create(annotation_set=landmarksets[2]) ) images[2].append(singlelandmarkbatches[2][-1].image) return MultipleLandmarkAnnotationSets( grader1=graders[0], grader2=graders[1], landmarkset1=landmarksets[0], landmarkset1images=images[0], landmarkset2=landmarksets[1], landmarkset2images=images[1], landmarkset3=landmarksets[2], landmarkset3images=images[2], )
def test_landmarks_single(self): u = UserFactory() i1 = ImageFactory() i2 = ImageFactory() las = LandmarkAnnotationSetFactory(grader=u) SingleLandmarkAnnotationFactory(annotation_set=las, image=i1) SingleLandmarkAnnotationFactory(annotation_set=las, image=i2) landmarks = RetinaImageSerializer(i1).data["landmark_annotations"] assert len(landmarks) == 1 assert landmarks == [i2.pk]
def test_landmarks_multiple(self): u = UserFactory() i1 = ImageFactory() img_pks = set() for _ in range(4): img = ImageFactory() las = LandmarkAnnotationSetFactory(grader=u) SingleLandmarkAnnotationFactory(annotation_set=las, image=img) SingleLandmarkAnnotationFactory(annotation_set=las, image=i1) img_pks.add(img.pk) landmarks = RetinaImageSerializer(i1).data["landmark_annotations"] assert len(landmarks) == 4 assert set(landmarks) == img_pks
def generate_annotation_set(retina_grader=False): grader = UserFactory() if retina_grader: add_to_graders_group([grader]) measurement = MeasurementAnnotationFactory(grader=grader) boolean = BooleanClassificationAnnotationFactory(grader=grader) integer = IntegerClassificationAnnotationFactory(grader=grader) polygon = PolygonAnnotationSetFactory(grader=grader) coordinatelist = CoordinateListAnnotationFactory(grader=grader) landmark = LandmarkAnnotationSetFactory(grader=grader) etdrs = ETDRSGridAnnotationFactory(grader=grader) # Create child models for polygon annotation set SinglePolygonAnnotationFactory.create_batch(10, annotation_set=polygon) # Create child models for landmark annotation set (3 per image) for i in range(5): image = ImageFactory() SingleLandmarkAnnotationFactory(annotation_set=landmark, image=image) return AnnotationSet( grader=grader, measurement=measurement, boolean=boolean, polygon=polygon, coordinatelist=coordinatelist, landmark=landmark, etdrs=etdrs, integer=integer, )
def create_load_data(data_type, ds, grader): if data_type == "Registration": model = LandmarkAnnotationSetFactory(grader=grader) SingleLandmarkAnnotationFactory( annotation_set=model, image=ds["image_cf"] ), if ds["archive"].name == "Australia": # Australia does not allow obs images so create a new cf image for Australia test img = ImageFactory(study=ds["study"]) SingleLandmarkAnnotationFactory(annotation_set=model, image=img) else: SingleLandmarkAnnotationFactory( annotation_set=model, image=ds["image_obs"] ), elif data_type == "ETDRS": model = ETDRSGridAnnotationFactory(grader=grader, image=ds["image_cf"]) elif data_type == "GA" or data_type == "kappa": model_macualar = PolygonAnnotationSetFactory( grader=grader, image=ds["image_cf"], name="macular" ) SinglePolygonAnnotationFactory(annotation_set=model_macualar) SinglePolygonAnnotationFactory(annotation_set=model_macualar) SinglePolygonAnnotationFactory(annotation_set=model_macualar) model_peripapillary = PolygonAnnotationSetFactory( grader=grader, image=ds["image_cf"], name="peripapillary" ) SinglePolygonAnnotationFactory(annotation_set=model_peripapillary) SinglePolygonAnnotationFactory(annotation_set=model_peripapillary) SinglePolygonAnnotationFactory(annotation_set=model_peripapillary) model = [model_macualar, model_peripapillary] elif data_type == "Measure": model = [ MeasurementAnnotationFactory(grader=grader, image=ds["image_cf"]), MeasurementAnnotationFactory(grader=grader, image=ds["image_cf"]), MeasurementAnnotationFactory(grader=grader, image=ds["image_cf"]), ] elif data_type == "Fovea": model = BooleanClassificationAnnotationFactory( grader=grader, image=ds["image_cf"], name="fovea_affected" ) return model
def generate_annotation_set(retina_grader=False, image=False): grader = UserFactory() if retina_grader: add_to_graders_group([grader]) create_options = {"grader": grader} if image: create_options_with_image = {"image": image, **create_options} else: create_options_with_image = create_options measurement = MeasurementAnnotationFactory(**create_options_with_image) boolean = BooleanClassificationAnnotationFactory( **create_options_with_image ) integer = IntegerClassificationAnnotationFactory( **create_options_with_image ) polygon = PolygonAnnotationSetFactory(**create_options_with_image) coordinatelist = CoordinateListAnnotationFactory( **create_options_with_image ) etdrs = ETDRSGridAnnotationFactory(**create_options_with_image) landmark = LandmarkAnnotationSetFactory(**create_options) # Create child models for polygon annotation set SinglePolygonAnnotationFactory.create_batch(10, annotation_set=polygon) # Create child models for landmark annotation set (3 per image) single_landmarks = [] for i in range(5): if i > 0 or not image: image = ImageFactory() single_landmarks.append( SingleLandmarkAnnotationFactory( annotation_set=landmark, image=image ) ) return AnnotationSet( grader=grader, measurement=measurement, boolean=boolean, polygon=polygon, coordinatelist=coordinatelist, landmark=landmark, singlelandmarks=single_landmarks, etdrs=etdrs, integer=integer, )