示例#1
0
def analyze(filename):
    pil_img = Image.open(filename)
    image = misc.fromimage(pil_img.convert("L"))

    isize = interface_size(image)

    # transfer distances
    # connectivity
    td1, connect1, td2, connect2 = transfer_distance(image)

    # get the domain size of the white phase
    # then invert the image to get the black domain size
    image = (image > image.mean())
    ads1, std1 = average_domain_size(image)
    inverted = (image < image.mean())
    ads2, std2 = average_domain_size(inverted)

    # bottlenecks of phase1, phase2
    b41, b21 = bottleneck_distribution(image)
    b42, b22 = bottleneck_distribution(inverted)

    # fraction of phase one
    phase1 = np.count_nonzero(image)
    fraction = float(phase1) / float(image.size)

    # Fractal dimension by box counting -- get the slope of the log/log fit
    bcd = -1.0 * box_counting_dimension(image)[0]

    # count the number of pepper defects
    spots = np.logical_xor(
        image, ndimage.binary_erosion(image, structure=np.ones((2, 2))))
    erosion_spots = np.count_nonzero(spots)
    spots = np.logical_xor(
        image, ndimage.binary_dilation(image, structure=np.ones((2, 2))))
    dilation_spots = np.count_nonzero(spots)
    spots = np.logical_xor(
        image,
        ndimage.binary_closing(
            image,
            structure=ndimage.morphology.generate_binary_structure(2, 1)))
    closure_spots = np.count_nonzero(spots)

    blur = modify.ublur_and_threshold(image, 3)
    x = np.logical_xor(image, blur)
    nzBlur = np.count_nonzero(x)

    results = {k: v for k, v in locals().iteritems() if k in keys}
    return ' '.join(['{%s:%s}' % (k, f)
                     for k, f in zip(keys, fmts)]).format(**results)
示例#2
0
def analyze(filename):
    pil_img = Image.open(filename)
    image = misc.fromimage(pil_img.convert("L"))

    isize = interface_size(image)

    # transfer distances
    # connectivity
    td1, connect1, td2, connect2 = transfer_distance(image)

    # get the domain size of the white phase
    # then invert the image to get the black domain size
    image = (image > image.mean())
    ads1, std1 = average_domain_size(image)
    inverted = (image < image.mean())
    ads2, std2 = average_domain_size(inverted)

    # bottlenecks of phase1, phase2
    b41, b21 = bottleneck_distribution(image)
    b42, b22 = bottleneck_distribution(inverted)

    # fraction of phase one
    phase1 = np.count_nonzero(image)
    fraction = float(phase1) / float(image.size)

    # Fractal dimension by box counting -- get the slope of the log/log fit
    bcd = -1.0* box_counting_dimension(image)[0]

    # count the number of pepper defects
    spots = np.logical_xor( image, ndimage.binary_erosion(image, structure=np.ones((2,2))) )
    erosion_spots = np.count_nonzero(spots)
    spots = np.logical_xor( image, ndimage.binary_dilation(image, structure=np.ones((2,2))) )
    dilation_spots = np.count_nonzero(spots)
    spots = np.logical_xor( image, ndimage.binary_closing(image, structure=ndimage.morphology.generate_binary_structure(2, 1)) )
    closure_spots = np.count_nonzero(spots)

    blur = modify.ublur_and_threshold(image, 3)
    x = np.logical_xor(image, blur)
    nzBlur = np.count_nonzero(x)

    results = {k : v for k, v in locals().iteritems() if k in keys}
    return ' '.join(['{%s:%s}' % (k, f) for k, f in zip(keys, fmts)]).format(**results)
示例#3
0
            if handle not in rescore_list:
                rescore_list.append(handle)

            # this works around a weird bug in scipy with 1-bit images
            pil = Image.open(handle)
            image = misc.fromimage(pil.convert("L"))

            mutation = random.randrange(7)
            debug('mutation={} path={}', mutation, handle)

            if mutation == 0:
                # gaussian blur
                image = modify.gblur_and_threshold(image, random.choice([2,3,4,5]))
            elif mutation == 1:
                # uniform blur
                image = modify.ublur_and_threshold(image, random.choice([2,3,4,5]))
            elif mutation == 2:
                # invert
                inverted = (image < image.mean())
                image = inverted
            elif mutation == 3:
                # add image-wide noise
                noise = np.random.random( image.shape )
                child = modify.blend_and_threshold(image, noise)
                image = child
            elif mutation == 4:
                # roughen the edges
                image = modify.roughen(image)
            elif mutation == 5:
                # rescale larger
                with warnings.catch_warnings(record=True) as warns:
示例#4
0
                rescore_list.append(handle)

            # this works around a weird bug in scipy with 1-bit images
            pil = Image.open(handle)
            image = misc.fromimage(pil.convert("L"))

            mutation = random.randrange(7)
            debug('mutation={} path={}', mutation, handle)

            if mutation == 0:
                # gaussian blur
                image = modify.gblur_and_threshold(image,
                                                   random.choice([2, 3, 4, 5]))
            elif mutation == 1:
                # uniform blur
                image = modify.ublur_and_threshold(image,
                                                   random.choice([2, 3, 4, 5]))
            elif mutation == 2:
                # invert
                inverted = (image < image.mean())
                image = inverted
            elif mutation == 3:
                # add image-wide noise
                noise = np.random.random(image.shape)
                child = modify.blend_and_threshold(image, noise)
                image = child
            elif mutation == 4:
                # roughen the edges
                image = modify.roughen(image)
            elif mutation == 5:
                # rescale larger
                with warnings.catch_warnings(record=True) as warns: