def sift_target():
    image = Image('../source/section_2_sentinel.tif', 'quickbird')
    image.precompute_normalization()

    clusters = sift_cluster([image])

    window = (slice(100, 125, 1), slice(100, 125, 1))
    ubyte = image['gray_ubyte']
    features = sift(ubyte[window], clusters)

    write_target(features, '../target/sift.nc', 'sift', window)
Example #2
0
def test_sift(image):
    dataset = Dataset("test/data/target/sift.nc", "r", format="NETCDF4")
    target = dataset.variables['sift'][:]

    slices = dataset.variables['window'][:]
    window = slice(*slices[0:3]), slice(*slices[3:6])

    clusters = sift_cluster([image])

    win = image['gray_ubyte'][window]
    features = sift(win, clusters)

    same = target == features

    assert same.all()
Example #3
0
def create_sift_feature(sat_image: SatelliteImage,
                        window_sizes,
                        image_name,
                        n_clusters=32,
                        cached=True) -> Sift:
    cache_key = "kmeans-sift-{}".format(image_name)

    if cached and cached_model_exists(cache_key):
        kmeans = load_cached_model(cache_key)
        print("Loaded cached kmeans {}".format(cache_key))
    else:
        print("Computing k-means model")
        kmeans = sift_cluster(sat_image, n_clusters=n_clusters)
        cache_model(kmeans, cache_key)

    feature = Sift(kmeans, windows=(window_sizes))

    return feature
        for test_image, train_images in cv_train_test_split_images(images):

            print("test im:{} train_ims:{}".format(test_image, train_images))

            image_name = test_image
            mask_full_path = "{base_path}/{image_name}_masked.tif".format(
                base_path=base_path, image_name=image_name)
            test_image_loaded = load_image(test_image)

            cached = True
            feature_set = FeatureSet()
            for feature_name, feature_scale in feature_names:
                feature_scale = tuple((fc, fc) for fc in feature_scale)

                if feature_name == "SIFT":
                    sift_clusters = sift_cluster(map(load_image, train_images))
                    # for fc in feature_scale:
                    sift = Sift(sift_clusters, windows=feature_scale)
                    feature_set.add(sift)
                    cached = False
                if feature_name == "TEXTON":
                    texton_clusters = texton_cluster(
                        map(load_image, train_images))
                    # for fc in feature_scale:
                    texton = Texton(texton_clusters, windows=feature_scale)
                    feature_set.add(texton)
                    cached = False
                if feature_name == "PANTEX":
                    # for fc in feature_scale:
                    pantex = Pantex(windows=feature_scale)
                    feature_set.add(pantex)