Convert will affect number of channel when image is simple
Convert will affect number of channel when image is simple
When I use convert or mogrify to modify some simple image like black, white or little object with large transparent area.
It will change its format, both windows explorer or OpenCV can read only one channel.
It seems like a good compress way to save space, but it will let program after it blow up.
It will change its format, both windows explorer or OpenCV can read only one channel.
It seems like a good compress way to save space, but it will let program after it blow up.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert will affect number of channel when image is simp
Some more information would help.
Can you supply an image that shows this problem, and the exact command you used, and the output file?
Can you supply an image that shows this problem, and the exact command you used, and the output file?
snibgo's IM pages: im.snibgo.com
Re: Convert will affect number of channel when image is simp
This is my test image and result
http://www.mediafire.com/?2qz74kq2aq95ti2
How I generate image using opencv:
How I convert image
Windows explorer shows black.png is 48bit and black_.png is 1bit
And OpenCV will get wrong format
Will output
Shows it get a one channel 8bit image and is totally not what I want.
I use OpenCV 2.4.3 and ImageMagick 6.8.1-10, both the latest stable version on Ubuntu 12.04.
http://www.mediafire.com/?2qz74kq2aq95ti2
How I generate image using opencv:
Code: Select all
Mat black(858, 2048, CV_16UC3, Scalar(0, 0, 0));
imwrite("black.png", black);
Code: Select all
convert black.png black_.dpx
convert black_.dpx black_.png
And OpenCV will get wrong format
Code: Select all
Mat image = imread("black_.png", -1);
cout<<image.cols<<"x"<<image.rows<<endl;
cout<<image.channels()<<endl;
cout<<image.depth()<<" "<<CV_8U<<" "<<CV_16U<<endl;
Code: Select all
2048x858
1
0 0 2
I use OpenCV 2.4.3 and ImageMagick 6.8.1-10, both the latest stable version on Ubuntu 12.04.
Re: Convert will affect number of channel when image is simp
Either the identify result is not the same.
identify black.png
black.png PNG 2048x858 2048x858+0+0 16-bit sRGB 10.3KB 0.000u 0:00.000
identify black_.png
black_.png PNG 2048x858 2048x858+0+0 8-bit RGB 2c 1.78KB 0.000u 0:00.000
identify black_.dpx
black_.dpx DPX 2048x858 2048x858+0+0 16-bit RGB 10.55MB 0.000u 0:00.000
identify black.png
black.png PNG 2048x858 2048x858+0+0 16-bit sRGB 10.3KB 0.000u 0:00.000
identify black_.png
black_.png PNG 2048x858 2048x858+0+0 8-bit RGB 2c 1.78KB 0.000u 0:00.000
identify black_.dpx
black_.dpx DPX 2048x858 2048x858+0+0 16-bit RGB 10.55MB 0.000u 0:00.000
Re: Convert will affect number of channel when image is simp
viewtopic.php?f=3&t=20431
I think this thread denote same bug
When the image is 8-bit this can be solve by PNG32, but there are no PNG64 or PNG48 for 16-bit image.
I think the correct way is not to change the format or add a option to keep it not over compress.
I think this thread denote same bug
When the image is 8-bit this can be solve by PNG32, but there are no PNG64 or PNG48 for 16-bit image.
I think the correct way is not to change the format or add a option to keep it not over compress.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert will affect number of channel when image is simp
try
convert black.png PNG24:black2.png
does that keep the file the way you want it?
convert black.png PNG24:black2.png
does that keep the file the way you want it?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert will affect number of channel when image is simp
Black.png has three channels of 1 bit each, indexing into a 16-bit-per-channel palette. As all the pixels are black, IM convert usually tries to optimize for size. It's still a valid PNG file, as far as I can see. However, ...
... will force a 16-bit palette, just like the source.
Code: Select all
"%IMG680%convert" b2.dpx -define png:bit-depth=16 b2.png
snibgo's IM pages: im.snibgo.com
Re: Convert will affect number of channel when image is simp
It is 3 channel right, but it becomes 8-bit and I want keep it 16bit and there are no PNG48 or PNG64 like I mention above.
And this method only works when I know what I exactly want, but at most time I just want it keep the same with original image.
The source is 3 channel 16-bit, I can get 3 channel 16-bit.
The source is 4 channel 16-bit, I can get 4 channel 16-bit.
The source is 3 channel 10-bit, I can get 3 channel 16-bit cause png doesn't support 10-bit but use 16-bit can prevent data loss.
The source is 4 channel 10-bit, I can get 4 channel 16-bit cause png doesn't support 10-bit but use 16-bit can prevent data loss.
The source is 3 channel 8-bit, I can get 3 channel 8-bit.
The source is 4 channel 8-bit, I can get 4 channel 8-bit.
And use only convert command or add a simple option but not case sensitive, just keep it like origin.
And this method only works when I know what I exactly want, but at most time I just want it keep the same with original image.
The source is 3 channel 16-bit, I can get 3 channel 16-bit.
The source is 4 channel 16-bit, I can get 4 channel 16-bit.
The source is 3 channel 10-bit, I can get 3 channel 16-bit cause png doesn't support 10-bit but use 16-bit can prevent data loss.
The source is 4 channel 10-bit, I can get 4 channel 16-bit cause png doesn't support 10-bit but use 16-bit can prevent data loss.
The source is 3 channel 8-bit, I can get 3 channel 8-bit.
The source is 4 channel 8-bit, I can get 4 channel 8-bit.
And use only convert command or add a simple option but not case sensitive, just keep it like origin.
Re: Convert will affect number of channel when image is simp
Yes, I know I can force it to any what I want (in most case).
But I just want it same as origin.
But I just want it same as origin.
Re: Convert will affect number of channel when image is simp
The simplest solution for you is probably to always write 16-bit RGBA.
convert in.png -define png:big-depth=16 -define png:color-type=6 out.png
Sometimes the output will be much larger in filesize than the input,
but your broken application should be able to read it.
convert in.png -define png:big-depth=16 -define png:color-type=6 out.png
Sometimes the output will be much larger in filesize than the input,
but your broken application should be able to read it.
Re: Convert will affect number of channel when image is simp
Beginning with ImageMagick-6.8.2-0 (SVN revision 10809), the PNG48 and PNG64 output sub-formatsglennrp wrote:The simplest solution for you is probably to always write 16-bit RGBA.
will be available, for writing 16-bit RGB and 16-bit RGBA, respectively. I plan to implement PNG00
as well, which will mean to inherit the color-type and bit-depth from the input PNG image.
Re: Convert will affect number of channel when image is simp
Thanks, I think PNG00 is really what I need, is this only works when input is png?glennrp wrote:Beginning with ImageMagick-6.8.2-0 (SVN revision 10809), the PNG48 and PNG64 output sub-formatsglennrp wrote:The simplest solution for you is probably to always write 16-bit RGBA.
will be available, for writing 16-bit RGB and 16-bit RGBA, respectively. I plan to implement PNG00
as well, which will mean to inherit the color-type and bit-depth from the input PNG image.
Re: Convert will affect number of channel when image is simp
Correct. The decoder and the encoder have to cooperate for PNG00 to work. Other decodersclhsieh wrote:Thanks, I think PNG00 is really what I need, is this only works when input is png?glennrp wrote:Beginning with ImageMagick-6.8.2-0 (SVN revision 10809), the PNG48 and PNG64 output sub-formatsglennrp wrote:The simplest solution for you is probably to always write 16-bit RGBA.
will be available, for writing 16-bit RGB and 16-bit RGBA, respectively. I plan to implement PNG00
as well, which will mean to inherit the color-type and bit-depth from the input PNG image.
don't store a color-type. Most store a depth, normally 8 or 16, which the PNG encoder will
recognize. Please note that if you rescale an 8-bit image, that operation might create
16-bit pixels due to interpolation of colors, which increases the depth to 16. Using the
-depth 8 option will prevent (or undo) that. The PNG color-type is meaningless to other
decoders, so they can't store an input color-type.
The PNG00 "format" is also available as of ImageMagick-6.8.2-0.