Jump to content

Grayscale Convert won´t work properly


Go to solution Solved by frio,

Recommended Posts

Hello guys, this is my help scream to u. Im building a mask for a programm, which has to be Grayscale and 8 Bit (8Bit 1 Channel). So I searched up and created my mask with black background and white squares (if it matters). Than I choose Layers -> Adjustments -> Black And White. Than I safe the image as png and choose 8 Bit. But than I look in Gimp and it is not grayscale, it is indexed (i dont know if its well translated. The Options are RGB, Grayscale and Indexed). So I tried saving it as bmp, with success, but my programm wont take bmp data, idk why. Is it possible with png in any way?  

Ty guys, sorry for my not well structured text/request

Screenshot 2024-09-13 085917.png

Link to comment
Share on other sites

1 hour ago, Razer said:

Is it possible with png in any way? 

 

You can use the OptiPNG FileType plugin:

 

1 hour ago, Razer said:

Than I choose Layers -> Adjustments -> Black And White.

 

Paint.NET works in RGB image mode only, it does not have a Grayscale mode. Adjustments -> Black And White changes the colors of the image, but the underlying image data is still stored as RGB.

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Link to comment
Share on other sites

1 hour ago, null54 said:

 

You can use the OptiPNG FileType plugin:

 

 

Paint.NET works in RGB image mode only, it does not have a Grayscale mode. Adjustments -> Black And White changes the colors of the image, but the underlying image data is still stored as RGB.


Thank you, but how does OptiPNG help me with the grayscale problem. I put the data in the right folder and now? nothing happens. I tried it with cmd optipng -o7 pic.png and it is getting compressed but the problem is still there? it is not in grayscale...
 

Link to comment
Share on other sites

2 hours ago, Razer said:

Thank you, but how does OptiPNG help me with the grayscale problem

 

OptiPNG doesn't support grayscale mode PNGs any more than paint.net's own PNG. You'll need an external tool, * I peeked at a couple online converters and some of them don't save the image in proper grayscale mode, but this one does: https://www.fileconverto.com/image-grayscale-online/

 

Take your indexed-grayscale image, convert it with that, and it'll be real grayscale afterwards. You can confirm with a hex editor: find the IHDR chunk which is followed by 4 bytes of width, 4 bytes of height, 1 byte of bit depth and then the byte you're interested in, the color type: paint.net's files are type 03 which means indexed palette, the converter's output is type 00 which means grayscale with no alpha. Type 04 would be grayscale with alpha, but I didn't test the previous converter if it handles transparency.

 

*) I did something wrong when I tested it earlier: OptiPNG filetype's (yes, the filetype exporter for paint.net, not the command line program itself) grayscale mode DOES work and produces a PNG file with color type 00. Grayscale with alpha produces a color type 04, so they are definitely valid grayscale mode files.

Edited by frio
I messed something up
Link to comment
Share on other sites

On 9/13/2024 at 1:02 PM, frio said:

 

OptiPNG doesn't support grayscale mode PNGs any more than paint.net's own PNG. You'll need an external tool, * I peeked at a couple online converters and some of them don't save the image in proper grayscale mode, but this one does: https://www.fileconverto.com/image-grayscale-online/

 

Take your indexed-grayscale image, convert it with that, and it'll be real grayscale afterwards. You can confirm with a hex editor: find the IHDR chunk which is followed by 4 bytes of width, 4 bytes of height, 1 byte of bit depth and then the byte you're interested in, the color type: paint.net's files are type 03 which means indexed palette, the converter's output is type 00 which means grayscale with no alpha. Type 04 would be grayscale with alpha, but I didn't test the previous converter if it handles transparency.

 

*) I did something wrong when I tested it earlier: OptiPNG filetype's (yes, the filetype exporter for paint.net, not the command line program itself) grayscale mode DOES work and produces a PNG file with color type 00. Grayscale with alpha produces a color type 04, so they are definitely valid grayscale mode files.

Hey the online converter works fine really thank you, but trying it with the plugin, I tried saving it with the setting Grayscale and no compression but it is still RGB in Gimp. How did you get the Grayscale Files?

Link to comment
Share on other sites

  • Solution
2 hours ago, Razer said:

Hey the online converter works fine really thank you, but trying it with the plugin, I tried saving it with the setting Grayscale and no compression but it is still RGB in Gimp. How did you get the Grayscale Files?

Looking at it again the OptiPNG export actually takes the mode you set it to only as a suggestion - setting it to grayscale when a paletted image is smaller produces a paletted image, setting it to RGB when grayscale is smaller makes a grayscale one, etc. For example a grayscale image with only 16 levels of gray will be smaller as a paletted 4-bit image (grayscale can only be 8 or 16 bits, so having 4 bits per pixel and a tiny palette header ends up being smaller in total). Turning off optimization in export won't help, then it just saves everything as 32-bit RGBA.

 

Looks like the online converter just does literally as told, removing color and saving as grayscale, so it's a safer bet.

Edit: if you want a local command program that can do the fix-up for you in bulk, ImageMagick has you covered. This command in Windows terminal/command prompt will make grayscaled copies of all PNGs in the current directory.

for %i in (*.png) do magick convert "%i" -colorspace gray "%~ni.gray.png"

An in-place conversion is even simpler, but of course that overwrites the original files so be careful.

magick mogrify -colorspace gray *.png

 

If you have a hex editor you can confirm the file type manually by looking at the outlined byte (red) in the IHDR chunk (chunk start green), if it's 00 or 04 it's grayscale.

image.png.1fb2718954d2740108853b21f202bab5.png

Edited by frio
  • Upvote 2
Link to comment
Share on other sites

2 hours ago, frio said:

Looking at it again the OptiPNG export actually takes the mode you set it to only as a suggestion - setting it to grayscale when a paletted image is smaller produces a paletted image, setting it to RGB when grayscale is smaller makes a grayscale one, etc. For example a grayscale image with only 16 levels of gray will be smaller as a paletted 4-bit image (grayscale can only be 8 or 16 bits, so having 4 bits per pixel and a tiny palette header ends up being smaller in total). Turning off optimization in export won't help, then it just saves everything as 32-bit RGBA.

 

Looks like the online converter just does literally as told, removing color and saving as grayscale, so it's a safer bet.

Edit: if you want a local command program that can do the fix-up for you in bulk, ImageMagick has you covered. This command in Windows terminal/command prompt will make grayscaled copies of all PNGs in the current directory.

for %i in (*.png) do magick convert "%i" -colorspace gray "%~ni.gray.png"

An in-place conversion is even simpler, but of course that overwrites the original files so be careful.

magick mogrify -colorspace gray *.png

 

If you have a hex editor you can confirm the file type manually by looking at the outlined byte (red) in the IHDR chunk (chunk start green), if it's 00 or 04 it's grayscale.

image.png.1fb2718954d2740108853b21f202bab5.png

Thank you so much for your help, it was really challenging for me. Now I am considering making an own plugin for Paint net, for using the magick api as saving option but i dont know. :D Cheers

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...