回答編集履歴
2
d
    
        answer	
    CHANGED
    
    | 
         @@ -35,15 +35,28 @@ 
     | 
|
| 
       35 
35 
     | 
    
         
             
                if r > 100 and b < 50 and g > 90:
         
     | 
| 
       36 
36 
     | 
    
         
             
                    return "VIOLET"
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
                return "OTHER" 
     | 
| 
      
 38 
     | 
    
         
            +
                return "OTHER"
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
            img = np.array(Image.open(" 
     | 
| 
      
 41 
     | 
    
         
            +
            img = np.array(Image.open("tttt.jpeg"))
         
     | 
| 
       42 
42 
     | 
    
         
             
            img = np.apply_along_axis(rgb_to_name, 2, img)
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
            from collections import Counter
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
       46 
46 
     | 
    
         
             
            for row in range(len(img)):
         
     | 
| 
       47 
47 
     | 
    
         
             
                cnt = Counter(img[row])
         
     | 
| 
       48 
     | 
    
         
            -
                print(f"row: {row}, count: {cnt}")
         
     | 
| 
      
 48 
     | 
    
         
            +
                print(f"row: {row}, count: {dict(cnt)}")
         
     | 
| 
      
 49 
     | 
    
         
            +
            ```
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            ```
         
     | 
| 
      
 52 
     | 
    
         
            +
            row: 0, count: {'WHITE': 289}
         
     | 
| 
      
 53 
     | 
    
         
            +
            row: 1, count: {'WHITE': 289}
         
     | 
| 
      
 54 
     | 
    
         
            +
            row: 2, count: {'WHITE': 289}
         
     | 
| 
      
 55 
     | 
    
         
            +
            row: 3, count: {'WHITE': 289}
         
     | 
| 
      
 56 
     | 
    
         
            +
            row: 4, count: {'WHITE': 289}
         
     | 
| 
      
 57 
     | 
    
         
            +
            row: 5, count: {'WHITE': 289}
         
     | 
| 
      
 58 
     | 
    
         
            +
            row: 6, count: {'WHITE': 289}
         
     | 
| 
      
 59 
     | 
    
         
            +
            row: 7, count: {'WHITE': 289}
         
     | 
| 
      
 60 
     | 
    
         
            +
            row: 8, count: {'WHITE': 280, 'CLEAM': 9}
         
     | 
| 
      
 61 
     | 
    
         
            +
            row: 9, count: {'WHITE': 20, 'CLEAM': 269}
         
     | 
| 
       49 
62 
     | 
    
         
             
            ```
         
     | 
1
d
    
        answer	
    CHANGED
    
    | 
         @@ -1,17 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            以下の手順でできます。
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            1. 画像の画素値 (R, G, B) を色の名前 (質問の if 文で定義されているもの) に変換する。 
         
     | 
| 
      
 3 
     | 
    
         
            +
            * 1. 画像の画素値 (R, G, B) を色の名前 (質問の if 文で定義されているもの) に変換する。 
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            → 色ごとに関数を適用するのに [numpy.apply_along_axis](https://docs.scipy.org/doc/numpy/reference/generated/numpy.apply_along_axis.html) を使う。
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
            2. 画像を行ごとに取得する。
         
     | 
| 
      
 7 
     | 
    
         
            +
            * 2. 画像を行ごとに取得する。
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
            ```
         
     | 
| 
      
 9 
     | 
    
         
            +
            ```python
         
     | 
| 
       10 
10 
     | 
    
         
             
            for row in range(len(img)):
         
     | 
| 
       11 
11 
     | 
    
         
             
                img(row)
         
     | 
| 
       12 
12 
     | 
    
         
             
            ```
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
            3. その行の色の種類及び数を数える。
         
     | 
| 
      
 14 
     | 
    
         
            +
            * 3. その行の色の種類及び数を数える。
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            collections.Countor を使う。
         
     | 
| 
       17 
17 
     | 
    
         |