How can I change my image's depth?
How can I change my image's depth?
I have an picture with the fomat "jpg" which depth is 8. So I write the following code:
string file_name = "d:\\test.jpg";
image.read(file_name);
image.write("d:\\test0.jpg");
I find the image "test0.jpg" which depth is 24. I want to konw how can I control the depth. Anyone can help me?
string file_name = "d:\\test.jpg";
image.read(file_name);
image.write("d:\\test0.jpg");
I find the image "test0.jpg" which depth is 24. I want to konw how can I control the depth. Anyone can help me?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How can I change my image's depth?
Both these images are probably 8 bits per channel, 3 channels, so 24 bits per pixel.
snibgo's IM pages: im.snibgo.com
Re: How can I change my image's depth?
I can see the image's property in windows system. One is depth 8, and other is depth 24.
In my code, I add some code to show depth info, as following:
string file_name = "d:\\test.jpg";
image.read(file_name);
image.depth(); //<------------this is 8
image.write("d:\\test0.jpg");
In my code, I add some code to show depth info, as following:
string file_name = "d:\\test.jpg";
image.read(file_name);
image.depth(); //<------------this is 8
image.write("d:\\test0.jpg");
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How can I change my image's depth?
Can you post URLs to test.jpg and test0.jpg?
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How can I change my image's depth?
It's better to put them on the web, so anyone can comment and learn.
But if the images are confidential, you can email them to me: snibgo at earthling dot net.
But if the images are confidential, you can email them to me: snibgo at earthling dot net.
snibgo's IM pages: im.snibgo.com
Re: How can I change my image's depth?
My main() code as following:
InitializeMagick("C:\\Program Files\\ImageMagick-6.6.2-Q16\\");
Image image;
// Read a file into image object
string file_name0 = "d:\\test.jpg";
image.depth(8);
image.read(file_name0);
image.depth(8);
cout<<image.depth()<<endl;
image.write("d:\\test10.jpg");
test.jpg-> code a722ccfa
http://61.dc.ftn.qq.com/ftn_handler/2c8 ... 309be66c7d
test10.jpg-> code d1e59c7f
http://61.dc.ftn.qq.com/ftn_handler/9f2 ... 49b64ef3e9
InitializeMagick("C:\\Program Files\\ImageMagick-6.6.2-Q16\\");
Image image;
// Read a file into image object
string file_name0 = "d:\\test.jpg";
image.depth(8);
image.read(file_name0);
image.depth(8);
cout<<image.depth()<<endl;
image.write("d:\\test10.jpg");
test.jpg-> code a722ccfa
http://61.dc.ftn.qq.com/ftn_handler/2c8 ... 309be66c7d
test10.jpg-> code d1e59c7f
http://61.dc.ftn.qq.com/ftn_handler/9f2 ... 49b64ef3e9
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How can I change my image's depth?
Your input file (test.jpg) has 32 different colours. ImageMagick reads it, decompresses, then compresses again. Jpeg compression will generally change the values of some pixels. If you save it as "quality 100" there are fewer changes. For this file, the number of colours does increase, but not beyond 255.
If you dislike jpeg messing with the number of colours, use a lossless format (such as PNG) instead.
If you dislike jpeg messing with the number of colours, use a lossless format (such as PNG) instead.
snibgo's IM pages: im.snibgo.com
Re: How can I change my image's depth?
That is a GIF file!!cnhome wrote:test.jpg-> code a722ccfa
If you convert a GIF with a 8bit palette to JPG

-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How can I change my image's depth?
Well spotted. So it is.That is a GIF file!!
snibgo's IM pages: im.snibgo.com