jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

Reloading saved image produces different image. #275

Closed vincematsko closed 4 years ago

vincematsko commented 4 years ago

In doing image processing, I am discretizing colors so that an image is rendered with just seven colors. I save the window using saveFrame(). I immediately reload into a different image, and find that the colors have changed slightly - close, but no longer discretized.

Is there a way to use saveFrame() which maintains the exact RGB values of each pixel? I thought this would be the default, but it seems that some other algorithm is used.

villares commented 4 years ago

Can you provide minimal code to reproduce?

What is the format you are saving the frame as? Have you tried .gif or .tga or anything else?

On Sat, 17 Aug 2019, 13:13 vincematsko, notifications@github.com wrote:

In doing image processing, I am discretizing colors so that an image is rendered with just seven colors. I save the window using saveFrame(). I immediately reload into a different image, and find that the colors have changed slightly - close, but no longer discretized.

Is there a way to use saveFrame() which maintains the exact RGB values of each pixel? I thought this would be the default, but it seems that some other algorithm is used.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jdf/Processing.py-Bugs/issues/275?email_source=notifications&email_token=AA4GADDORXFZJT6K5GLREC3QFAPULA5CNFSM4IMPZ562YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HFZHSGQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4GADA3BCR3ZTNWAB3DY4LQFAPULANCNFSM4IMPZ56Q .

vincematsko commented 4 years ago

Here is a screen shot - hard to reproduce with a few lines of code. I can attach the .pyde file and image used, if necessary. The basic issue is that on frame 1, I save an image and print RGB values of pixel 0. On frame 2, I load the saved image and print RGB values of pixel 0, and they've changed.

processing

jdf commented 4 years ago

As @villares suggested, JPEGs are lossy, and there's little relationship between input pixel and output pixel. You'll need to use a lossless format such as PNG.

villares commented 4 years ago

I'm unable to examine this right now, but I'm afraid there is no problem in Processing, the thing is you are saving in .jpg which compresses and manipulates colours on save!

On Sat, 17 Aug 2019, 16:03 vincematsko, notifications@github.com wrote:

Here is a screen shot - hard to reproduce with a few lines of code. I can attach the .pyde file and image used, if necessary. The basic issue is that on frame 1, I save an image and print RGB values of pixel 0. On frame 2, I load the saved image and print RGB values of pixel 0, and they've changed.

[image: processing] https://user-images.githubusercontent.com/11161159/63216173-89a50e80-c0ff-11e9-8f2a-46cde563a315.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jdf/Processing.py-Bugs/issues/275?email_source=notifications&email_token=AA4GADFR2OJUHA3EB5KEY23QFBDOHA5CNFSM4IMPZ562YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4QRQ5Y#issuecomment-522262647, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4GADAH67GA3V56ADWXQE3QFBDOHANCNFSM4IMPZ56Q .