| 67 | |
| 68 | # Step Sorting Algorithm |
| 69 | def step(bgr, repetitions=1): |
| 70 | b, g, r = bgr |
| 71 | # lum is calculated as per the way the humans view the colors |
| 72 | lum = math.sqrt(0.241 * r + 0.691 * g + 0.068 * b) |
| 73 | |
| 74 | # conversion of rgb to hsv values |
| 75 | h, s, v = colorsys.rgb_to_hsv( |
| 76 | r, g, b |
| 77 | ) # h,s,v is a better option for classifying each color |
| 78 | |
| 79 | # Repetitions are taken to decrease the noise |
| 80 | h2 = int(h * repetitions) |
| 81 | v2 = int(v * repetitions) |
| 82 | |
| 83 | # To get a smoother color band |
| 84 | if h2 % 2 == 1: |
| 85 | v2 = repetitions - v2 |
| 86 | lum = repetitions - lum |
| 87 | |
| 88 | return h2, lum, v2 |
| 89 | |
| 90 | |
| 91 | # Threshold set for avoiding extreme sorting of the pixels |