@@ -350,3 +350,71 @@ def test_math_algorithm(name, numpy_method, options):
350350 out .array , numpy_method (img .array , axis = 0 , keepdims = True , ** options )
351351 )
352352 assert out .array [0 , 1 , 1 ] is numpy .ma .masked
353+
354+
355+ def test_bitonal_algorithm ():
356+ """Test bitonal algorithm."""
357+ algo = default_algorithms .get ("bitonal" )()
358+
359+ arr = numpy .ma .MaskedArray (
360+ numpy .zeros ((1 , 256 , 256 ), dtype = "uint8" ),
361+ mask = numpy .zeros ((1 , 256 , 256 ), dtype = "bool" ),
362+ )
363+ arr .data [0 , 100 :200 , 100 :200 ] = 200
364+ arr .mask [0 , 120 :130 , 120 :130 ] = True
365+ img = ImageData (arr )
366+ out = algo (img )
367+ assert out .array .shape == (1 , 256 , 256 )
368+ assert out .array .dtype == "uint8"
369+ assert out .array [0 , 125 , 125 ] is numpy .ma .masked
370+ assert out .array [0 , 150 , 150 ] == 255
371+ assert out .array [0 , 50 , 50 ] == 0
372+
373+ arr = numpy .ma .MaskedArray (
374+ numpy .zeros ((3 , 256 , 256 ), dtype = "uint8" ),
375+ mask = numpy .zeros ((3 , 256 , 256 ), dtype = "bool" ),
376+ )
377+ arr .data [:, 100 :200 , 100 :200 ] = 200
378+ arr .mask [0 , 120 :130 , 120 :130 ] = True
379+ img = ImageData (arr )
380+ out = algo (img )
381+ assert out .array .shape == (1 , 256 , 256 )
382+ assert out .array .dtype == "uint8"
383+ assert out .array [0 , 125 , 125 ] is numpy .ma .masked
384+ assert out .array [0 , 150 , 150 ] == 255
385+ assert out .array [0 , 50 , 50 ] == 0
386+
387+ arr = numpy .ma .MaskedArray (
388+ numpy .zeros ((4 , 256 , 256 ), dtype = "uint8" ),
389+ mask = numpy .zeros ((4 , 256 , 256 ), dtype = "bool" ),
390+ )
391+ img = ImageData (arr )
392+ with pytest .raises (ValueError ):
393+ out = algo (img )
394+
395+
396+ def test_grayscale_algorithm ():
397+ """Test grayscale algorithm."""
398+ algo = default_algorithms .get ("grayscale" )()
399+
400+ arr = numpy .ma .MaskedArray (
401+ numpy .zeros ((3 , 256 , 256 ), dtype = "uint8" ),
402+ mask = numpy .zeros ((3 , 256 , 256 ), dtype = "bool" ),
403+ )
404+ arr .data [:, 100 :200 , 100 :200 ] = 200
405+ arr .mask [0 , 120 :130 , 120 :130 ] = True
406+ img = ImageData (arr )
407+ out = algo (img )
408+ assert out .array .shape == (1 , 256 , 256 )
409+ assert out .array .dtype == "uint8"
410+ assert out .array [0 , 125 , 125 ] is numpy .ma .masked
411+ assert out .array [0 , 150 , 150 ] != 0
412+ assert out .array [0 , 50 , 50 ] == 0
413+
414+ arr = numpy .ma .MaskedArray (
415+ numpy .zeros ((2 , 256 , 256 ), dtype = "uint8" ),
416+ mask = numpy .zeros ((2 , 256 , 256 ), dtype = "bool" ),
417+ )
418+ img = ImageData (arr )
419+ with pytest .raises (ValueError ):
420+ out = algo (img )
0 commit comments