Page 1 of 1

How can I change my image's depth?

Posted: 2010-07-13T07:01:44-07:00
by cnhome
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?

Re: How can I change my image's depth?

Posted: 2010-07-13T07:22:38-07:00
by snibgo
Both these images are probably 8 bits per channel, 3 channels, so 24 bits per pixel.

Re: How can I change my image's depth?

Posted: 2010-07-13T19:10:48-07:00
by cnhome
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");

Re: How can I change my image's depth?

Posted: 2010-07-13T19:30:51-07:00
by snibgo
Can you post URLs to test.jpg and test0.jpg?

Re: How can I change my image's depth?

Posted: 2010-07-13T19:38:44-07:00
by cnhome
I can email to u

May I?

Re: How can I change my image's depth?

Posted: 2010-07-14T06:27:17-07:00
by snibgo
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.

Re: How can I change my image's depth?

Posted: 2010-07-16T00:24:00-07:00
by cnhome
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

Re: How can I change my image's depth?

Posted: 2010-07-16T10:23:45-07:00
by snibgo
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.

Re: How can I change my image's depth?

Posted: 2010-07-16T15:56:41-07:00
by Drarakel
cnhome wrote:test.jpg-> code a722ccfa
That is a GIF file!!
If you convert a GIF with a 8bit palette to JPG :), it has to be stored with 3x8 bit (unless the image is grayscale - but this one isn't).

Re: How can I change my image's depth?

Posted: 2010-07-16T16:03:43-07:00
by snibgo
That is a GIF file!!
Well spotted. So it is.

Re: How can I change my image's depth?

Posted: 2010-07-19T23:04:18-07:00
by cnhome
My mistake. Thanks a lot! :)