Page 1 of 1
Converting color images
Posted: 2009-06-04T09:13:32-07:00
by yeller
Hello,
I've inherited an application that uses the following command to create thumbnails:
convert -sample 400x440 infiile.tif outfile.tif
This works excellent for black and white images. However, when color gets involved, the output file is not good. Part of the problem is that this is part an automated process, therefore I either use the same command for both black and white images and color, or I have to identify before hand that the image is color and therefore use a different command.
I need the thumbnails created as quickly as possible, with the smallest filesize possible, but with acceptable quality (I realize quality affects filesize).
Therefore, I either need a way to
1) change the sample command so it creates good looking thumbnails or,
2) quickly identify that the original file is color and then use a different convert command for that case to obtain a good looking thumnbail or,
3) some other idea
Thank You
Re: Converting color images
Posted: 2009-06-04T09:44:48-07:00
by fmw42
convert infile.tif -thumbnail 400x440 outfile.tif
not sure why you are using -sample as that will change the size and the density. -scale would be faster, but may not give good results for color. so I suggest using -thumbnail.
see
http://www.imagemagick.org/script/comma ... #thumbnail
http://www.imagemagick.org/script/comma ... php#resize
http://www.imagemagick.org/script/comma ... .php#scale
http://www.imagemagick.org/script/comma ... php#sample
Re: Converting color images
Posted: 2009-06-04T10:12:29-07:00
by yeller
Ok, I went ahead and tried -resize and -scale and both of those did not give me good thumbnails at all.
I had tried the -thumbnail option before but that creates a much larger file than does -sample for black and white images. Also, sample is faster than thumbnail.
I could use the thumbnail for color alone, but I'd somehow have to identify what images are color and therefore need the -thumbnail conversion.
Re: Converting color images
Posted: 2009-06-04T12:48:40-07:00
by fmw42
see the string format %[channels]. it will tell you RGB or Gray
color=`convert rose: -format "%[channels]" info:`
echo $color
rgb
color=`convert rose: -colorspace gray -format "%[channels]" info:`
echo $color
gray
http://www.imagemagick.org/script/escape.php
But if you have a b/w image that is truecolor and not pseudocolor or bilevel, then it will report rgb
So I am not sure if this will really help.
Re: Converting color images
Posted: 2009-06-04T14:04:53-07:00
by yeller
I've tried the command 'identify -format "%[channels]" test.tif', from the command line, but I don't get any output. Do I have to use this in a program so a variable can capture the output?
Re: Converting color images
Posted: 2009-06-04T16:06:11-07:00
by fmw42
identify -format "%[channels]" rose:
works for me from the command line as is and returns rgb.
But that feature was added only some time ago. I believe at about IM 6.4.1-9. So I suspect your IM is too old. What version are you using? Can you upgrade?
Re: Converting color images
Posted: 2009-06-04T18:33:09-07:00
by anthony
Shrinking Black and white images, or more specifically line drawings
is always very difficult, and I can see why you opted to use -sample in that case.
The problem is that -resize (includes -thumbnail) and -scale will average colors, reducing thin lines to near invisible greys.
If the image only consists of line and no areas of foreground color, then you may be able to -normalize or -level and -threshold the image so as to enhance the lines. but it would still not be very good.
If the lines are well spaced, an alternative is to do a morphologial erode (black on white) or dilate (white on black) to make the lines thicker and thus more visible before shrinking the image.
(search the forum for these words to find a number of discussions of doing this)
A staged process of slowly shrinking the image in say 25% increments amy also work well in this case.
As for the output image size. that may be solved by adjusting the output image format, either to another image format that is more suitable to images containing greys. OR thresholding and color reducing the results (say -colors or -posterize, but without dither) so that it will compress better, or save in a different style, such as using a color table, like used by the GIF image format.
Re: Converting color images
Posted: 2009-06-05T06:31:24-07:00
by yeller
Per fmw42:
I'm currently at IM version 6.2.8.0. But the rgb doesn't work for me anyhow (I found this out by upgrading a dev box to the latest version and tested). However, when I perform "identify -verbose file1" I get something outputed that would help a lot, and that is the compression tag. If only I could get this output faster than running -verbose (it takes my machine about 5 seconds).
Re: Converting color images
Posted: 2009-06-05T09:06:56-07:00
by fmw42
see string format %C for compression. does that help?
http://www.imagemagick.org/script/escape.php
Re: Converting color images
Posted: 2009-06-05T09:57:45-07:00
by yeller
Actually, I tried that and it didn't work for the version I was using. I did however find out about %r, that displays image class and colorspace. That appears to be working for me as my black and whites are identified as the colorspace gray and my colors are id'd as colorspace rgb.
Thanks for the help