@@ -634,11 +634,10 @@ def sepia(image: Image.Image) -> Image.Image:
634634 if image .mode != "RGB" :
635635 image = image .convert ("RGB" )
636636
637- width , height = image .size
638- out = Image .new ("RGB" , (width , height ))
637+ out = Image .new ("RGB" , image .size )
639638
640- for x in range (width ):
641- for y in range (height ):
639+ for x in range (image . width ):
640+ for y in range (image . height ):
642641 r , g , b = cast (tuple [int , int , int ], image .getpixel ((x , y )))
643642
644643 tr = int (0.393 * r + 0.769 * g + 0.189 * b )
@@ -665,22 +664,22 @@ def sobel(image: Image.Image) -> Image.Image:
665664 :return: An image.
666665 """
667666 image = image .convert ("L" )
668- width , height = image .size
669667
670668 Kx = [[- 1 , 0 , 1 ], [- 2 , 0 , 2 ], [- 1 , 0 , 1 ]]
671669
672670 Ky = [[1 , 2 , 1 ], [0 , 0 , 0 ], [- 1 , - 2 , - 1 ]]
673671
674- out = Image .new ("L" , ( width , height ) )
672+ out = Image .new ("L" , image . size )
675673
676- for y in range (1 , height - 1 ):
677- for x in range (1 , width - 1 ):
674+ for y in range (1 , image . height - 1 ):
675+ for x in range (1 , image . width - 1 ):
678676
679677 gx = gy = 0
680678
681679 for dy in (- 1 , 0 , 1 ):
682680 for dx in (- 1 , 0 , 1 ):
683- v = cast (int , image .getpixel ((x + dx , y + dy )))
681+ v = image .getpixel ((x + dx , y + dy ))
682+ assert isinstance (v , int )
684683
685684 kx = Kx [dy + 1 ][dx + 1 ]
686685 ky = Ky [dy + 1 ][dx + 1 ]
@@ -702,8 +701,8 @@ def _glow_mask(edge_img: Image.Image) -> Image.Image:
702701 :return: An image.
703702 """
704703
705- def screen_point (x ) :
706- return 255 - ((255 - x ) * (255 - x ) // 255 )
704+ def screen_point (value : int ) -> int :
705+ return 255 - ((255 - value ) * (255 - value ) // 255 )
707706
708707 return edge_img .point (screen_point )
709708
@@ -716,12 +715,12 @@ def _neon_colorize(mask: Image.Image, color: tuple[int, int, int]) -> Image.Imag
716715 :return: An image
717716 """
718717 r , g , b = color
719- width , height = mask .size
720- out = Image .new ("RGB" , (width , height ))
718+ out = Image .new ("RGB" , mask .size )
721719
722- for y in range (height ):
723- for x in range (width ):
724- v = cast (int , mask .getpixel ((x , y )))
720+ for y in range (mask .height ):
721+ for x in range (mask .width ):
722+ v = mask .getpixel ((x , y ))
723+ assert isinstance (v , int )
725724
726725 out .putpixel (
727726 (x , y ),
@@ -751,11 +750,10 @@ def _neon_blend(
751750 if alpha > 1 :
752751 alpha = 1
753752
754- width , height = original .size
755- out = Image .new ("RGB" , (width , height ))
753+ out = Image .new ("RGB" , original .size )
756754
757- for y in range (height ):
758- for x in range (width ):
755+ for y in range (original . height ):
756+ for x in range (original . width ):
759757 r1 , g1 , b1 = cast (tuple [int , int , int ], original .getpixel ((x , y )))
760758 r2 , g2 , b2 = cast (tuple [int , int , int ], neon .getpixel ((x , y )))
761759
0 commit comments