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
Converting color images
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting color images
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
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
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting color images
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.
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
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting color images
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?
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?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Converting color images
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Converting color images
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).
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).
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting color images
see string format %C for compression. does that help? http://www.imagemagick.org/script/escape.php
Re: Converting color images
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
Thanks for the help