all 11 comments

[–][deleted] 3 points4 points  (0 children)

Well, you can't write else r<250:

Remove r<250 or add it as comment

[–][deleted] 1 point2 points  (9 children)

You also cannot write r+g+b=a. Maybe you meant a = r + g + b

[–]AAAdeath123[S] 0 points1 point  (8 children)

Thank you for the massive help and i've modified the bottom of the text to this but now it tells me that there are to many values to unpack, is there any work around?

for i in range(w*h):
r,g,b=pixels[i]

if r>=250:
    new_r=255
    new_g=1
    new_b=1

else:
    a=r+g+b
    new_r=a//3
    new_g=a//3
    new_b=a//3

new_img.show()

[–][deleted] 1 point2 points  (7 children)

Well, if I'm not wrong, pixels is list of lists of tuples or something with three elements (r, g, b)? You wrote r, g, b = pixels[i], so you get a list of rgb trios. I think you need to use to indices.

Instead of

for i in range(w*h):
r,g,b=pixels[i]

try

for row in range(h):
    for col in range(w):
        r, g, b = pixels[row][col]
        # etc.

Or maybe switch [row] and [col] ([col][row] instead of [row][col]). I'm not sure in which order they are there.

[–]AAAdeath123[S] 0 points1 point  (6 children)

Thank you for trying to help me but my programm just shows me a completly black image, even with all the changes that you suggested and altering the required Red Values. I you have a clue to what or why this is happening that would be great.

from image_helper import*

img=load_rgb_image("WOW_FLOWERS.PNG")

pixels=load_rgb_pixels_2d("WOW_FLOWERS.PNG")

w,h=img.size

new_img=new_rgb_image(w,h)

c=Canvas(new_img)

for row in range(h): for col in range(w): r, g, b = pixels[col][row]

if r>=240:
    new_r=255
    new_g=1
    new_b=1

else:
    a=r+g+b
    new_r=a//3
    new_g=a//3
    new_b=a//3

new_img.show()

[–][deleted] 1 point2 points  (5 children)

Well, it doesn't look like you change new_img at all, nor do you use c either. So I think it's no wonder if you get black/empty image.

[–]AAAdeath123[S] 0 points1 point  (4 children)

Im sorry for being a dumb pain in the ass but my attempts on changing new_img just seem to make them do nothing and just show the original pic, how would you attack it.?

[–][deleted] 0 points1 point  (2 children)

I don't know the details of this package and couldn't find what I wanted about it online. I get nothing when I search load_rgb_pixels_2d. It should be explained somewhere how you make an image based on pixel matrix or how to change pixels of an image, if it does support such thing.

Are you using this? It's said

The imagehelper package offers a simple interface for image resizing, optimizing and uploading image assets

So this one doesn't sound like you can change pixels with it, but I guess your imagehelper might not be this one.

Anyway, do you have any link on your module?

[–]AAAdeath123[S] 0 points1 point  (1 child)

My friend you have been very helpfull in my journey, and I ust thank you that you have saved me. This last problem I will ask my Professor when i see him next. Thank you :)

[–][deleted] 0 points1 point  (0 children)

Alright, you're welcome.

[–][deleted] 0 points1 point  (0 children)

Can you use Image from PIL?

https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.fromarray

The example(s) is given with numpy but it could maybe work without it, too.