Esempio n. 1
0
def test():
    """ Tests for bytescale(¬) adapted from `scipy.misc.pilutil` doctests,
        q.v. https://git.io/fhkHI supra.
    """
    from instakit.utils.static import asset
    
    image_paths = list(map(
        lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(map(
        lambda image_path: Mode.RGB.open(image_path),
            image_paths))
    
    # print()
    print("«TESTING: BYTESCALE UTILITY FUNCTION»")
    
    image = numpy.array((91.06794177,   3.39058326,  84.4221549,
                         73.88003259,  80.91433048,   4.88878881,
                         51.53875334,  34.45808177,  27.5873488)).reshape((3, 3))
    assert numpy.all(
           bytescale(image) == numpy.array((255,   0, 236,
                                            205, 225,   4,
                                            140,  90,  70),
                                           dtype=uint8_t).reshape((3, 3)))
    assert numpy.all(
           bytescale(image,
                     high=200,
                     low=100) == numpy.array((200, 100, 192,
                                              180, 188, 102,
                                              155, 135, 128),
                                             dtype=uint8_t).reshape((3, 3)))
    assert numpy.all(
           bytescale(image,
                     cmin=0,
                     cmax=255) == numpy.array((91,  3, 84,
                                               74, 81,  5,
                                               52, 34, 28),
                                              dtype=uint8_t).reshape((3, 3)))
    print("«SUCCESS»")
    print()
    
    # print()
    print("«TESTING: FROMIMAGE»")
    
    image_arrays = list(map(
        lambda image_input: fromimage(image_input),
            image_inputs))
    
    for idx, image_array in enumerate(image_arrays):
        assert image_array.dtype == uint8_t
        assert image_array.shape[0] == image_inputs[idx].size[1]
        assert image_array.shape[1] == image_inputs[idx].size[0]
    
    print("«SUCCESS»")
    print()
Esempio n. 2
0
def test():
    from pprint import pprint
    from instakit.utils.static import asset
    from instakit.processors.halftone import Atkinson

    image_paths = list(
        map(lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(
        map(lambda image_path: Mode.RGB.open(image_path), image_paths))

    for image_input in image_inputs[:2]:
        OverprintFork(Atkinson).process(image_input).show()

        print('Creating OverprintFork and BandFork with Atkinson ditherer...')
        overatkins = OverprintFork(Atkinson)
        forkatkins = BandFork(Atkinson)

        print(
            'Processing image with BandForked Atkinson in default (RGB) mode...'
        )
        forkatkins.process(image_input).show()
        forkatkins.mode = 'CMYK'
        print('Processing image with BandForked Atkinson in CMYK mode...')
        forkatkins.process(image_input).show()
        forkatkins.mode = 'RGB'
        print('Processing image with BandForked Atkinson in RGB mode...')
        forkatkins.process(image_input).show()

        overatkins.mode = 'CMYK'
        print(
            'Processing image with OverprintFork-ized Atkinson in CMYK mode...'
        )
        overatkins.process(image_input).show()

        print('Attempting to reset OverprintFork to RGB mode...')
        import traceback, sys
        try:
            overatkins.mode = 'RGB'
            overatkins.process(image_input).show()
        except:
            print(">>>>>>>>>>>>>>>>>>>>> TRACEBACK <<<<<<<<<<<<<<<<<<<<<")
            traceback.print_exc(file=sys.stdout)
            print("<<<<<<<<<<<<<<<<<<<<< KCABECART >>>>>>>>>>>>>>>>>>>>>")
            print('')

    bandfork = BandFork(None)
    pprint(bandfork)

    print(image_paths)
Esempio n. 3
0
def test():
    from instakit.utils.static import asset
    from instakit.utils.mode import Mode

    image_paths = list(
        map(lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(
        map(lambda image_path: Mode.RGB.open(image_path), image_paths))

    for image_input in image_inputs:
        image_input.show()
        SquareCrop().process(image_input).show()

    print(image_paths)
Esempio n. 4
0
def test():
    """ Tests for bytescale(¬) adapted from `scipy.misc.pilutil` doctests,
        q.v. https://git.io/fhkHI supra.
    """
    from instakit.utils.static import asset

    image_paths = list(
        map(lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(
        map(lambda image_path: Mode.RGB.open(image_path), image_paths))

    # print()
    print("«TESTING: BYTESCALE UTILITY FUNCTION»")

    image = numpy.array(
        (91.06794177, 3.39058326, 84.4221549, 73.88003259, 80.91433048,
         4.88878881, 51.53875334, 34.45808177, 27.5873488)).reshape((3, 3))
    assert numpy.all(
        bytescale(image) == numpy.array((255, 0, 236, 205, 225, 4, 140, 90,
                                         70),
                                        dtype=uint8_t).reshape((3, 3)))
    assert numpy.all(
        bytescale(image, high=200, low=100) == numpy.array(
            (200, 100, 192, 180, 188, 102, 155, 135,
             128), dtype=uint8_t).reshape((3, 3)))
    assert numpy.all(
        bytescale(image, cmin=0, cmax=255) == numpy.array(
            (91, 3, 84, 74, 81, 5, 52, 34, 28), dtype=uint8_t).reshape((3, 3)))
    print("«SUCCESS»")
    print()

    # print()
    print("«TESTING: FROMIMAGE»")

    image_arrays = list(
        map(lambda image_input: fromimage(image_input), image_inputs))

    for idx, image_array in enumerate(image_arrays):
        assert image_array.dtype == uint8_t
        assert image_array.shape[0] == image_inputs[idx].size[1]
        assert image_array.shape[1] == image_inputs[idx].size[0]

    print("«SUCCESS»")
    print()
Esempio n. 5
0
def test():
    from instakit.utils.static import asset
    from instakit.utils.mode import Mode

    image_paths = list(
        map(lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(
        map(lambda image_path: Mode.RGB.open(image_path), image_paths))

    noises = [
        GaussianNoise, PoissonNoise, GaussianLocalVarianceNoise, SaltNoise,
        PepperNoise, SaltAndPepperNoise, SpeckleNoise
    ]

    for idx, image_input in enumerate(image_inputs + image_inputs[:2]):
        for NoiseProcessor in noises:
            NoiseProcessor().process(image_input).show()

    print(image_paths)
Esempio n. 6
0
def test():
    curve_sets = CurveSet.instakit_curve_sets()

    image_paths = list(
        map(lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(
        map(lambda image_path: Mode.RGB.open(image_path), image_paths))

    for image_input in image_inputs[:1]:
        image_input.show()
        for curve_set in curve_sets:
            curve_set.process(image_input).show()

    print(curve_sets)
    print(image_paths)

    import tempfile
    temppath = tempfile.mktemp(suffix='.acv')
    assert not CurveSet(path=temppath).file_exists
Esempio n. 7
0
def test():
    curve_sets = CurveSet.instakit_curve_sets()
    
    image_paths = list(map(
        lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(map(
        lambda image_path: Mode.RGB.open(image_path),
            image_paths))
    
    for image_input in image_inputs[:1]:
        image_input.show()
        for curve_set in curve_sets:
            curve_set.process(image_input).show()
    
    print(curve_sets)
    print(image_paths)
    
    import tempfile
    temppath = tempfile.mktemp(suffix='.acv')
    assert not CurveSet(path=temppath).file_exists
Esempio n. 8
0
def test():
    from instakit.utils.static import asset

    image_paths = list(
        map(lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(
        map(lambda image_path: Mode.RGB.open(image_path), image_paths))

    for image_input in image_inputs:
        image_input.show()

        # Atkinson(threshold=128.0).process(image_input).show()
        # FloydSteinberg(threshold=128.0).process(image_input).show()
        # SlowFloydSteinberg(threshold=128.0).process(image_input).show()

        # CMYKAtkinson().process(image_input).show()
        # CMYKFloydsterBill().process(image_input).show()
        CMYKDotScreen(sample=10, scale=4).process(image_input).show()

    print(image_paths)
Esempio n. 9
0
def test():
    from instakit.utils.static import asset
    from instakit.utils.mode import Mode
    from clu.predicates import isslotted

    image_paths = list(
        map(lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(
        map(lambda image_path: Mode.RGB.open(image_path), image_paths))

    processors = (Contour(), Detail(), Emboss(), EdgeEnhance(),
                  EdgeEnhanceMore(), FindEdges(), Smooth(), SmoothMore(),
                  Sharpen(), UnsharpMask(), GaussianBlur(sigmaX=3),
                  SimpleGaussianBlur(radius=3))

    for processor in processors:
        assert isslotted(processor)

    for image_input in image_inputs:
        # image_input.show()
        # for processor in processors:
        #     processor.process(image_input).show()

        # image_input.show()
        # Contour().process(image_input).show()
        # Detail().process(image_input).show()
        # Emboss().process(image_input).show()
        # EdgeEnhance().process(image_input).show()
        # EdgeEnhanceMore().process(image_input).show()
        # FindEdges().process(image_input).show()
        # Smooth().process(image_input).show()
        # SmoothMore().process(image_input).show()
        # Sharpen().process(image_input).show()
        # UnsharpMask().process(image_input).show()
        GaussianBlur(sigmaX=3).process(image_input).show()
        # SimpleGaussianBlur(radius=3).process(image_input).show()

    print(image_paths)
Esempio n. 10
0
def test():
    from instakit.utils.static import asset
    from instakit.utils.mode import Mode
    
    image_paths = list(map(
        lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(map(
        lambda image_path: Mode.RGB.open(image_path),
            image_paths))
    
    noises = [GaussianNoise,
              PoissonNoise,
              GaussianLocalVarianceNoise,
              SaltNoise,
              PepperNoise,
              SaltAndPepperNoise,
              SpeckleNoise]
    
    for idx, image_input in enumerate(image_inputs + image_inputs[:2]):
        for NoiseProcessor in noises:
            NoiseProcessor().process(image_input).show()
    
    print(image_paths)
Esempio n. 11
0
 def builtin(cls, name):
     print("Reading curves [builtin] %s%s" % (name, cls.dotacv))
     acv_path = asset.path(cls.acv, "%s%s" % (name, cls.dotacv))
     out = cls(acv_path)
     out._is_builtin = True
     return out
Esempio n. 12
0
def test():
    from instakit.utils.static import asset
    from itertools import chain
    from os.path import relpath
    from pprint import pprint

    start = "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages"

    image_paths = list(
        map(lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(
        map(lambda image_path: Mode.RGB.open(image_path), image_paths))
    # print("len:", len(list(image_paths)), len(list(image_inputs)), len(list(callables)))

    print(
        '\t<<<<<<<<<<<<<<<------------------------------------------------------>>>>>>>>>>>>>>>'
    )
    print()

    functions = (gcr, ucr)
    processors = (BasicGCR(), BasicUCR(), Mode.CMYK)
    callables = chain((processor.process for processor in processors),
                      functions)

    image_components = zip(image_paths, image_inputs, callables)

    for path, image, process_functor in image_components:
        print("«TESTING: %s»" % relpath(path, start=start))
        print()
        tup = image.size + (image.mode, )
        print("¬ Input: %sx%s %s" % tup)
        print("¬ Calling functor on image…")
        result = process_functor(image)
        tup = result.size + (result.mode, )
        print("¬ Output: %sx%s %s" % tup)
        print("¬ Displaying…")
        print()
        result.show()

    print("«¡SUCCESS!»")
    print()

    print("«TESTING: MANUAL CALLABLES»")
    # print()

    if len(image_inputs):
        image = image_inputs.pop()

        # Test GCR function:
        gcred = gcr(image)
        assert gcred.mode == Mode.CMYK.value.mode
        assert Mode.of(gcred) is Mode.CMYK
        # gcred.show()

        # close image:
        image.close()

    if len(image_inputs):
        image = image_inputs.pop()

        # Test UCR function:
        ucred = ucr(image)
        assert ucred.mode == Mode.CMYK.value.mode
        assert Mode.of(ucred) is Mode.CMYK
        # ucred.show()

        # close image:
        image.close()

    if len(image_inputs):
        image = image_inputs.pop()

        # Test GCR processor:
        gcr_processor = BasicGCR()
        gcred = gcr_processor.process(image)
        assert gcred.mode == Mode.CMYK.value.mode
        assert Mode.of(gcred) is Mode.CMYK
        # gcred.show()

        # close image:
        image.close()

    if len(image_inputs):
        image = image_inputs.pop()

        # Test UCR processor:
        ucr_processor = BasicUCR()
        ucred = ucr_processor.process(image)
        assert ucred.mode == Mode.CMYK.value.mode
        assert Mode.of(ucred) is Mode.CMYK
        # ucred.show()

        # close image:
        image.close()

    print("«¡SUCCESS!»")
    print()

    print(
        '\t<<<<<<<<<<<<<<<------------------------------------------------------>>>>>>>>>>>>>>>'
    )
    print()

    pprint(list(relpath(path, start=start) for path in image_paths))
    print()

    print("«TESTING: DemoUCR ALGORITHM-STAGE TRACE PRINTER»")
    print()

    print(DemoUCR("#BB2F53"))
    print()

    print(DemoUCR(0x6F2039))
    print()
Esempio n. 13
0
class Grid(Fork):
    pass

class Sequence(Fork):
    pass

ChannelOverprinter = OverprintFork

if __name__ == '__main__':
    from pprint import pprint
    from instakit.utils.static import asset
    from instakit.processors.halftone import Atkinson
    
    image_paths = list(map(
        lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(map(
        lambda image_path: Mode.RGB.open(image_path),
            image_paths))
    
    for image_input in image_inputs[:2]:
        OverprintFork(Atkinson).process(image_input).show()
        
        print('Creating OverprintFork and BandFork with Atkinson ditherer...')
        overatkins = OverprintFork(Atkinson)
        forkatkins = BandFork(Atkinson)
        
        print('Processing image with BandForked Atkinson in default (RGB) mode...')
        forkatkins.process(image_input).show()
        forkatkins.mode = 'CMYK'
Esempio n. 14
0
def test():
    from pprint import pprint

    print("«KNOWN IMAGE MODES»")
    print()

    for m in Mode:
        print("• %10s\t ∞%5s/%s : %s » %s" %
              (m.label, m.basemode, m.basetype, m.dtype_code(), m.dtype))

    print()
    """
    •   1 (MONO)	 ∞    L/L : |b1 » bool
    •          L	 ∞    L/L : |u1 » uint8
    •          I	 ∞    L/I : <i4 » int32
    •          F	 ∞    L/F : <f4 » float32
    •          P	 ∞  RGB/L : |u1 » uint8
    •        RGB	 ∞  RGB/L : |u1 » uint8
    •       RGBX	 ∞  RGB/L : |u1 » uint8
    •       RGBA	 ∞  RGB/L : |u1 » uint8
    •       CMYK	 ∞  RGB/L : |u1 » uint8
    •      YCbCr	 ∞  RGB/L : |u1 » uint8
    •        LAB	 ∞  RGB/L : |u1 » uint8
    •        HSV	 ∞  RGB/L : |u1 » uint8
    •       RGBa	 ∞  RGB/L : |u1 » uint8
    •         LA	 ∞    L/L : |u1 » uint8
    •         La	 ∞    L/L : |u1 » uint8
    •         PA	 ∞  RGB/L : |u1 » uint8
    • I;16 (I16)	 ∞    L/L : <u2 » uint16
    • I;16L (I16L)	 ∞    L/L : <u2 » uint16
    • I;16B (I16B)	 ∞    L/L : >u2 » >u2
    
    """

    print("«TESTING: split_abbreviations()»")

    assert split_abbreviations('RGB') == ('R', 'G', 'B')
    assert split_abbreviations('CMYK') == ('C', 'M', 'Y', 'K')
    assert split_abbreviations('YCbCr') == ('Y', 'Cb', 'Cr')
    assert split_abbreviations('sRGB') == ('R', 'G', 'B')
    assert split_abbreviations('XYZZ') == ('X', 'Y', 'Z')
    assert split_abbreviations('I;16L') == ('I', )

    assert split_abbreviations('RGB') == Mode.RGB.bands
    assert split_abbreviations('CMYK') == Mode.CMYK.bands
    assert split_abbreviations('YCbCr') == Mode.YCbCr.bands
    assert split_abbreviations('I;16L') == Mode.I16L.bands
    assert split_abbreviations('sRGB') == Mode.RGB.bands
    # assert split_abbreviations('XYZ') == ('X', 'Y', 'Z')

    print("«SUCCESS»")
    print()

    # print(Mode.I16L.bands)
    # print(Mode.RGB.bands)

    pprint(list(Mode))
    print()

    assert Mode(10) == Mode.LAB
    # assert hasattr(Mode.RGB, '__slots__')

    print()

    print("«TESTING: CONTEXT-MANAGED IMAGE MODES»")
    print()
    from instakit.utils.static import asset

    image_paths = list(
        map(lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(
        map(lambda image_path: Mode.RGB.open(image_path), image_paths))

    for image in image_inputs:
        with Mode.L.ctx(image) as grayscale:
            assert Mode.of(grayscale.image) is Mode.L
            print(grayscale.image)
            grayscale.image = Mode.MONO.process(grayscale.image)
        print()

    print("«SUCCESS»")
    print()
Esempio n. 15
0
 def builtin(cls, name):
     print(f"Reading curves [builtin] {name}{cls.dotacv}")
     acv_path = asset.path(cls.acv, f"{name}{cls.dotacv}")
     out = cls(acv_path)
     out._is_builtin = True
     return out
Esempio n. 16
0
def test():
    
    print("«KNOWN IMAGE MODES»")
    print()
    
    for m in Mode:
        print("• %10s\t ∞%5s/%s : %s » %s" % (m.label,
                                              m.basemode,
                                              m.basetype,
                                              m.dtype_code(),
                                              m.dtype))
    
    print()
    
    """
    •   1 (MONO)	 ∞    L/L : |b1 » bool
    •          L	 ∞    L/L : |u1 » uint8
    •          I	 ∞    L/I : <i4 » int32
    •          F	 ∞    L/F : <f4 » float32
    •          P	 ∞  RGB/L : |u1 » uint8
    •        RGB	 ∞  RGB/L : |u1 » uint8
    •       RGBX	 ∞  RGB/L : |u1 » uint8
    •       RGBA	 ∞  RGB/L : |u1 » uint8
    •       CMYK	 ∞  RGB/L : |u1 » uint8
    •      YCbCr	 ∞  RGB/L : |u1 » uint8
    •        LAB	 ∞  RGB/L : |u1 » uint8
    •        HSV	 ∞  RGB/L : |u1 » uint8
    •       RGBa	 ∞  RGB/L : |u1 » uint8
    •         LA	 ∞    L/L : |u1 » uint8
    •         La	 ∞    L/L : |u1 » uint8
    •         PA	 ∞  RGB/L : |u1 » uint8
    • I;16 (I16)	 ∞    L/L : <u2 » uint16
    • I;16L (I16L)	 ∞    L/L : <u2 » uint16
    • I;16B (I16B)	 ∞    L/L : >u2 » >u2
    
    """
    
    print("«TESTING: split_abbreviations()»")
    
    assert split_abbreviations('RGB') == ('R', 'G', 'B')
    assert split_abbreviations('CMYK') == ('C', 'M', 'Y', 'K')
    assert split_abbreviations('YCbCr') == ('Y', 'Cb', 'Cr')
    assert split_abbreviations('sRGB') == ('R', 'G', 'B')
    assert split_abbreviations('XYZZ') == ('X', 'Y', 'Z')
    assert split_abbreviations('I;16L') == ('I',)
    
    assert split_abbreviations('RGB') == Mode.RGB.bands
    assert split_abbreviations('CMYK') == Mode.CMYK.bands
    assert split_abbreviations('YCbCr') == Mode.YCbCr.bands
    assert split_abbreviations('I;16L') == Mode.I16L.bands
    assert split_abbreviations('sRGB') == Mode.RGB.bands
    # assert split_abbreviations('XYZ') == ('X', 'Y', 'Z')
    
    print("«SUCCESS»")
    
    # print(Mode.I16L.bands)
    # print(Mode.RGB.bands)
    # print(list(Mode))
    # print()
    
    assert Mode(10) == Mode.LAB
    assert hasattr(Mode.RGB, '__slots__')
    
    print()
    
    print("«TESTING: CONTEXT-MANAGED IMAGE MODES»")
    print()
    from instakit.utils.static import asset
    
    image_paths = list(map(
        lambda image_file: asset.path('img', image_file),
            asset.listfiles('img')))
    image_inputs = list(map(
        lambda image_path: Mode.RGB.open(image_path),
            image_paths))
    
    for image in image_inputs:
        with Mode.L(image, verbose=True) as grayscale:
            assert Mode.of(grayscale.image) is Mode.L
            print(grayscale.image)
            grayscale.image = Mode.MONO.process(grayscale.image)
        print()
    
    print("«SUCCESS»")
    print()