Jump to content

Saving png rounds a pixel with a value of 010101 down to 000000


drakbar
Go to solution Solved by toe_head2001,

Recommended Posts

So I am working on images for machine learning, and absolute pixels values matter. Somewhere between 250 x 250 pixels and 350 x 350 pixels small color values such as 010101 is rounded down to 000000.

 

Steps to reproduce.

Create an canvas of 350x350 pixels.

Use the fill tool to make the entire canvas black (color value 000000).

Use the color picker to verify that the canvas is 000000.

Select the pencil tool.

Change your primary color to 010101.

Pencil the top left 3x3 pixels.

Use the color picker to verify that those pixel are 010101 and the rest are 000000.

Save the file. (as png)

Close the file.

Open the file.

Use the color picker to verify the color in the top left corner.

 

Expected Value: 010101

Observed Value: 000000

 

I am not sure what the issue is. My guess is that it has something to do with compression. This behavior hasn't been observed below 250x250 pixels. Also if you make the entire canvas the value 010101, save, close, and reopen then the value will be what is expected.

 

I am pretty sure that the pixel value is changed in the during the process of saving. I have loaded the file programmatically using python and looked at the pixel values while the file was open in Paint.net just after the file was saved. The pixel values observed during that time were 000000. This would rule out the values being change during close or loading back the image into Paint.net.

 

The reason I believe that it has to do with compression is that if the entire canvas is 010101 then saving, exiting, and loading the file doesn't change the pixel value.

I am not sure if my save settings are wrong, but I would like to figure out how to save these file without losing the data. I am able to perform this function in MS Paint which hurts my soul very deeply because I love Paint.net.<3 

 

 

 

  • Upvote 1
Link to comment
Share on other sites

@drakbar, Are you using the latest version of PDN? There was a bug in "Auto Detect" bit-depth that were fixed in v4.3.

 

If you are using the latest version (currently v4.3.4), then I'll be sure to take a look at getting a fix in for v4.3.5.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

  • 2 weeks later...

This appears to be a bug in WIC (Windows Imaging Component), the system library that handles the low-level saving and loading of many of Paint.NET's built-in image types.

 

I may be able to work around this if I can detect the mistake and use a higher bit-depth ...

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Okay I have a fix for this.

 

WIC's format converter for 8-bit to <8-bit is buggy. I already had my own converter for 8-bit to 4-bit, and I was able to easily adapt it to handle 2-bit and 1-bit.

  • Like 1

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...