回答編集履歴
1
fix answer
    
        answer	
    CHANGED
    
    | @@ -1,17 +1,19 @@ | |
| 1 1 | 
             
            `slice_image()`の切り抜き部分を概説すると
         | 
| 2 2 | 
             
            ```Python
         | 
| 3 | 
            -
            if ar.shape[0] < ar.shape[1]: #  | 
| 3 | 
            +
            if ar.shape[0] < ar.shape[1]: # 横長画像であれば
         | 
| 4 | 
            -
                middle = ar.shape[1] // 2 #  | 
| 4 | 
            +
                middle = ar.shape[1] // 2 # 横のサイズの半分を取得
         | 
| 5 5 | 
             
                half = desired_size // 2 # 欲しい画像サイズの半分を取得
         | 
| 6 6 |  | 
| 7 | 
            -
                images.append(Image.fromarray(ar[:, :desired_size])) # 欲しい画像サイズで | 
| 7 | 
            +
                images.append(Image.fromarray(ar[:, :desired_size])) # 欲しい画像サイズで横に左からdesired_size分を切り抜き
         | 
| 8 | 
            -
                images.append(Image.fromarray(ar[:, middle-half:middle+half])) # 画像 | 
| 8 | 
            +
                images.append(Image.fromarray(ar[:, middle-half:middle+half])) # 画像横方向に中心middleから-half,中心middleからhalfにかけて切り抜き.middleを中心としてサイズはdesired_sizeになる.
         | 
| 9 | 
            -
                images.append(Image.fromarray(ar[:, ar.shape[1]-desired_size:ar.shape[1]])) # 欲しい画像サイズで | 
| 9 | 
            +
                images.append(Image.fromarray(ar[:, ar.shape[1]-desired_size:ar.shape[1]])) # 欲しい画像サイズで横に下からdesired_size分を切り抜き
         | 
| 10 10 | 
             
            ```
         | 
| 11 | 
            -
            になります. | 
| 11 | 
            +
            になります.同様に`else`句のあとは縦長画像に対する処理を行います.
         | 
| 12 12 |  | 
| 13 | 
            -
             | 
| 13 | 
            +
            この関数で画像を切り抜こうとすると,重複部分があることを許容して長方形画像を3枚の正方形画像に切り分けることになりますね.
         | 
| 14 14 |  | 
| 15 | 
            +
            長辺が`desired_size`の2倍なら,半分ずつ被った画像が生成されることになりますし,3倍以上なら重複なしで画像が生成されることになります.下の画像では前者で例示してみました.
         | 
| 16 | 
            +
             | 
| 15 17 | 
             
            
         | 
| 16 18 |  | 
| 17 19 | 
             
            `resize_pad_image()`は上下左右Zero Paddingするだけの処理になってますね.
         | 
