예제 #1
0
def amplitude_mean(N=100):
    amps = lambda: util.images().pad(100, 100).map(transform.amplitude)

    logger.info("Calculating mean amplitude")
    mean_a = util.mean(amps(), np.zeros((100, 100)))

    # distance
    d = np.linalg.norm
    dist = (d(amp - mean_a) for amp in util.progress(amps()))

    logger.info(f"Finding {N} farthest away from the mean")
    oddities = nlargest(N, zip(dist, util.image_ids()))

    logger.info(f"Finished amplitude mean outliers")
    return oddities
예제 #2
0
def centered_mean(N=100):
    centered = lambda: util.images().pad(100, 100).map(transform.center)

    logger.info("Calculating mean centered image")
    mean_c = util.mean(centered(), np.zeros((100, 100)))

    # distance
    d = np.linalg.norm
    dist = (d(img - mean_c) for img in util.progress(centered()))

    logger.info(f"Finding {N} farthest away from the mean")
    oddities = nlargest(N, zip(dist, util.image_ids()))

    logger.info(f"Finished centered mean outliers")
    return oddities
예제 #3
0
def mean(N=100):
    images = lambda: util.images().pad(100, 100)

    logger.info("Calculating mean image")
    mean = util.mean(images())

    # max-correlation of mean
    d = util.max_correlation
    d = np.linalg.norm
    maxcorr = (d(img - mean) for img in util.progress(images()))

    logger.info(f"Finding {N} with least correlation with the mean")
    oddities = nlargest(N, zip(maxcorr, util.image_ids()))

    logger.info(f"Finished maxcorr outliers")
    return oddities
예제 #4
0
def histogram_mean(N=100):
    hists = lambda: util.images().map(transform.smoothen).map(transform.grayscale)

    logger.info("Calculating mean histogram")
    mean_h = util.mean(hists(), np.zeros((256)))

    # distance
    d = np.linalg.norm
    d = util.max_correlation1d
    dist = (d(hist, mean_h) for hist in util.progress(hists()))

    logger.info(f"Finding {N} farthest away from the mean")
    oddities = nlargest(N, zip(dist, util.image_ids()))

    logger.info(f"Finished histogram mean outliers")
    return oddities
예제 #5
0
def rotated_mean(N=100):
    images = lambda: util.images().pad(100, 100)
    angles = lambda: util.images().pad(100, 100).map(transform.PCA_angle)
    rotated = lambda: util.seq(transform.rotate(img, ang) for img, ang in zip(images(), angles()))

    logger.info("Calculating mean rotated image")
    mean_r = util.mean(rotated(), np.zeros((100, 100)))

    # distance
    d = np.linalg.norm
    dist = (d(img - mean_r) for img in util.progress(rotated()))

    logger.info(f"Finding {N} farthest away from the mean")
    oddities = nlargest(N, zip(dist, util.image_ids()))

    logger.info(f"Finished rotated mean outliers")
    return oddities
예제 #6
0
def frequency_mean(N=100):
    phases = lambda: util.images().pad(100, 100).map(transform.phase)

    logger.info("Calculating mean phase")
    mean_p = util.mean(phases(), np.zeros((100, 100)))

    # mean_p = transform.shape(mean_p, shape="circle", mask_value=0, radius=25)

    # distance
    d = np.linalg.norm
    d = util.max_correlation
    dist = (-d(phase, mean_p) for phase in util.progress(phases()))

    logger.info(f"Finding {N} farthest away from the mean")
    oddities = nlargest(N, zip(dist, util.image_ids()))

    logger.info(f"Finished phase mean outliers")
    return oddities
예제 #7
0
def PCA_angle(N=100):
    """
    Computes the mean angle, the finds N angles that deviates the most from
    the mean, modulo pi.

    There was an issue with the angle of the PCA to be inverted 180 degrees.
    This shouldn't affect the mean too much, but caused some images to be
    incorrectly classified as anomalies. Thus, we consider only angles
    between [-90, 90).
    """

    angles = lambda: util.images().pad(100, 100).map(transform.PCA_angle)

    logger.info("Calculating PCA angle mean")
    mean = util.angle_mean(angles())

    # distances from mean angle
    distances = (util.circle_dist(mean, angle) for angle in angles())

    logger.info(f"Finding {N} angles farthest away from mean")
    oddities = nlargest(N, zip(distances, util.image_ids()))

    logger.info(f"Finished PCA angle outliers")
    return oddities