|
1 |
| -# Author Sri Vennela Vaishnapu |
2 |
| - |
3 |
| -# bi toning algorithm |
4 |
| -# blue = 255.0f / blueLevelFloat * (float )pixelBuffer[k]; |
5 |
| -# green = 255.0f / greenLevelFloat * (float)pixelBuffer[k + 1]; |
6 |
| -# red = 255.0f / redLevelFloat * (float)pixelBuffer[k + 2]; |
7 |
| -# if (blue > 255) {blue = 255;} |
8 |
| -# else if (blue < 0) {blue = 0;} |
9 |
| -# if (green > 255) {green = 255;} |
10 |
| -# else if (green < 0) {green = 0;} |
11 |
| -# if (red > 255) {red = 255;} |
12 |
| -# else if (red < 0) {red = 0;} |
13 |
| -from PIL import Image |
14 |
| -i = Image.open("lena.jpg") |
15 |
| -print(i.format,i.size,i.mode) |
16 |
| -pixels = i.load() # this is not a list, nor is it list()'able |
17 |
| -width, height = i.size |
18 |
| -j=Image.new(i.mode,i.size) |
19 |
| -blueLevelFloat=input("enter the color level for blue which is ranging from 0 to 255") |
20 |
| -greenLevelFloat=input("enter the color level for green which is ranging from 0 to 255") |
21 |
| -redLevelFloat=input("enter the color level for red which is ranging from 0 to 255") |
22 |
| -for x in range(width): |
23 |
| - for y in range(height): |
24 |
| - cpixel = pixels[x, y] |
25 |
| - #cpixel[0] contains red value cpixel[1] contains green value |
26 |
| - #cpixel[2] contains blue value cpixel[3] contains alpha value |
27 |
| - outputBlue = int(255.0 / blueLevelFloat * cpixel[0]); |
28 |
| - outputGreen = int(255.0 / greenLevelFloat * cpixel[1]); |
29 |
| - outputRed = int(255.0 / redLevelFloat * cpixel[2]); |
30 |
| - if(outputRed>255): |
31 |
| - outputRed=255 |
32 |
| - elif(outputRed<0): |
33 |
| - outputRed=0 |
34 |
| - if(outputGreen>255): |
35 |
| - outputGreen=255 |
36 |
| - elif(outputGreen<0): |
37 |
| - outputGreen=0 |
38 |
| - if(outputBlue>255): |
39 |
| - outputBlue=255 |
40 |
| - elif(outputBlue<0): |
41 |
| - outputBlue=0 |
42 |
| - j.putpixel((x,y),(outputRed,outputGreen,outputBlue)) |
43 |
| -j.save('colourbal.png') |
44 |
| -
|
| 1 | +# Author Sri Vennela Vaishnapu |
| 2 | + |
| 3 | +# bi toning algorithm |
| 4 | +# blue = 255.0f / blueLevelFloat * (float )pixelBuffer[k]; |
| 5 | +# green = 255.0f / greenLevelFloat * (float)pixelBuffer[k + 1]; |
| 6 | +# red = 255.0f / redLevelFloat * (float)pixelBuffer[k + 2]; |
| 7 | +# if (blue > 255) {blue = 255;} |
| 8 | +# else if (blue < 0) {blue = 0;} |
| 9 | +# if (green > 255) {green = 255;} |
| 10 | +# else if (green < 0) {green = 0;} |
| 11 | +# if (red > 255) {red = 255;} |
| 12 | +# else if (red < 0) {red = 0;} |
| 13 | +from PIL import Image |
| 14 | +i = Image.open("lena.jpg") |
| 15 | +print(i.format,i.size,i.mode) |
| 16 | +pixels = i.load() # this is not a list, nor is it list()'able |
| 17 | +width, height = i.size |
| 18 | +j=Image.new(i.mode,i.size) |
| 19 | +blueLevelFloat=input("enter the color level for blue which is ranging from 0 to 255") |
| 20 | +greenLevelFloat=input("enter the color level for green which is ranging from 0 to 255") |
| 21 | +redLevelFloat=input("enter the color level for red which is ranging from 0 to 255") |
| 22 | +for x in range(width): |
| 23 | + for y in range(height): |
| 24 | + cpixel = pixels[x, y] |
| 25 | + #cpixel[0] contains red value cpixel[1] contains green value |
| 26 | + #cpixel[2] contains blue value cpixel[3] contains alpha value |
| 27 | + outputBlue = int(255.0 / blueLevelFloat * cpixel[0]); |
| 28 | + outputGreen = int(255.0 / greenLevelFloat * cpixel[1]); |
| 29 | + outputRed = int(255.0 / redLevelFloat * cpixel[2]); |
| 30 | + if(outputRed>255): |
| 31 | + outputRed=255 |
| 32 | + elif(outputRed<0): |
| 33 | + outputRed=0 |
| 34 | + if(outputGreen>255): |
| 35 | + outputGreen=255 |
| 36 | + elif(outputGreen<0): |
| 37 | + outputGreen=0 |
| 38 | + if(outputBlue>255): |
| 39 | + outputBlue=255 |
| 40 | + elif(outputBlue<0): |
| 41 | + outputBlue=0 |
| 42 | + j.putpixel((x,y),(outputRed,outputGreen,outputBlue)) |
| 43 | +j.save('colourbal.png') |
| 44 | + |
0 commit comments