My goal is to create a Tiff image that natively holds uncompressed (or with lossless compression) YCbCr data inside (since the original image is YUV420 and IMO it would be a poor choice to upsample and convert to RGB).
I’m able to create (using imagemagick for instance) a valid YCbCr Tiff with a JPEG compressed data. When I try uncompressed / deflate / lzw I get a broken image (neither windows image viewer nor photoshop can open it). On page 94 of the TIFF 6.0 spec (under “Minimum Requirements for YCbCr Images”):
Compression = none (1), LZW (5) or JPEG (6). SHORT.
What’s wrong? Is there a Tiff extension which says that YCbCr color space is supported only when using jpeg compression?
Thanks,
Mark.
Command that works:
convert infileRGB.tif -colorspace ycbcr -compress jpeg outfileYCbCr.tif
Commands that don't work (broken tiff):
convert infileRGB.tif -colorspace ycbcr -compress none outfileYCbCr.tif
convert infileRGB.tif -colorspace ycbcr -compress lzw outfileYCbCr.tif
Related
I am using ImageMagick to convert png files to tiff. But after conversion the file size seems to increase by a huge amount? Any suggestion on what am i doing wrong here?
Command that I am using for conversion is : convert tiftest1.png tiftest2.png output_file.tif
PNG files are analysed (filtered) on a line-by-line basis to see how best each line can be compressed relative to the previous one, then compressed. TIFF files, in general, are not.
You need to consider whether you can accept lossless or lossy compression and then tell the TIFF encoder.
If only lossless compression is acceptable:
magick input1.png input2.png -compress LZW result.tif
If lossy compression is acceptable (and compatible with downstream needs):
magick input1.png input2.png -compress JPEG result.tif
Check actual compression used in a file with:
magick identify -verbose image.tif
Check available types of compression with:
magick identify -list compress
When converting to tiff, ImageMagick produces a non-compressed file by default. You can tell it to use LZW or ZIP or JPEG or other compressions. PNG is always compressed.
I'm trying to find the right command for compressing png and jpg files good enough for Google Page speed.
I'm using the following from my OSX termial:
convert -strip -quality 85 imagesource.png imagesource_optimized.png
The result is no difference in file size between the original and "optimized version. Am Is there a different command I can use?
Compression is fundamentally different between PNG and JPEG because PNG is lossless and JPEG is lossy.
With a JPEG the -quality parameter specifies how much quality should be retained.
With a PNG file, the -quality parameter specifies the strategy and the amount of time/effort zlib can spend to optimise your image - think gzip --best versus gzip --fast.
See https://www.imagemagick.org/script/command-line-options.php#quality
For PNG, I suggest pngcrush which you can install with homebrew using:
brew install pngcrush
For JPEG, either use -quality or specify a maximum size:
# Specify by quality
convert input.jpg -strip -quality 75% output.jpg
# Specify maximum size
convert input.jpg -strip -define jpeg:extent=300k output.jpg
Compression is fundamentally different between PNG and JPEG because PNG is lossless and JPEG is lossy.
Using ImageMagick's convert utility to convert some scanned jpg files to pbm files.
However, even if the option -quality 100 is used, the pbm's resolution still looks worse than the original scanned jpg file.
Worse, the scanned jpg file is a colored one, while the converted pbm is black and white.
Info of original jpg:
image size: 2256 × 1568 pixels
dpi: 300 pixels/inch
color model: RGB
info of the converted pbm:
image size: 2256 × 1568 pixels
dpi: 72 pixels/inch
color model: Gray
Currently, here is what I did to convert the format:
qiang#bonjour:~/scan$ convert scan000.jpg scan000.pbm
Am I missing any option to use with convert? As I mentioned earlier, -quality 100 had been tried, but to no avail.
Using ImageMagick, I think you want to output to PPM not PBM. Try
convert image.jpg image.ppm
or try the ascii version by using
convert image.jpg -compress none image.ppm
PBM is binary (black/white) and PGM is grayscale. If you want to keep color, then you need to use PPM.
Unfortunately, I believe that ImageMagick can only read DJVU format images. So you cannot write to it directly from ImageMagick.
I printed two files one in a tiff format and another in a jpeg format. My question is will there by any difference in Quantity of ink used for both or in other ways will JPEG or Tiff consume more ink ?
ok, i'll bite. The file format themselves have no effect.That which could cause differences:
A) The application used to print the file.
B) The format of the file. A CMYK TIFF or JPEG might print differently than the same image in an RGB TIFF or YCbCr JPEG.
I have a batch script that converts my PNG-24 (with Transparency) images to 50% and 25% size (for mobile development). Usually these images have colors in them but now I am trying to convert an image that has no colors and ImageMagick keeps changing the colorspace profile to "Gray", which messes up my image in the 3d engine I'm using (Unity).
I have tried forcing it to use type TrueColor, colorspace sRGB, and the sRGB.icc profile (the one included with OSX) but it doesn't seem to care. It still changes it to Gray.
> convert old.png -profile srgb.icc -colorspace sRGB -type TrueColor new.png
> identify *.png
old.png PNG 140x140 140x140+0+0 8-bit sRGB 3.68KB 0.000u 0:00.000
new.png PNG 140x140 140x140+0+0 8-bit sRGB 256c 2.33KB 0.000u 0:00.000
ImageMagick still identifies it as an 8-bit sRGB image but it puts "256c" after it which I'm assuming means it has reduced it down to 256 colors, which I don't want either. When I look at the image in OSX Preview.app, it says it is using the Gray color profile. The image also visually looks a lot different.
Here is the image I'm using: https://dl.dropbox.com/u/59304/old.png
There is a duplicate question here, ImageMagick Reduces Colorspace to Gray, but the answer does not work for me and I don't have enough reputation to comment on his answer, unfortunately. I imagine my case is different because I'm using PNG and not JPG.
Version: ImageMagick 6.8.0-7 2013-01-02 Q16 http://www.imagemagick.org
Features: OpenCL
edit- After reading the ImageMagick forums as specified in one of the answers, it looks like just prepending PNG32: or PNG24: to the output file solves the problem.
The proper way to keep a grayscale PNG as RGB is to use PNG24:result.png
Input:
convert lena.png -colorspace gray PNG24:lenag_rgb.png
identify -verbose lenag_rgb.png
Image: lenag_rgb.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 256x256+0+0
Units: Undefined
Colorspace: sRGB
Type: Grayscale
So as you see above, Colorspace is RGB while the type is Grayscale.
For other image formats such as JPG and TIFF, use -define colorspace:auto-grayscale=false along with -type truecolor.
You may pass -set colorspace:auto-grayscale off to convert to disable automatic conversion of RGB channels to a single grayscale channel.
This solution was not yet available at the time of your question, but was introduced in 2015 with version 6.9.2:
2015-07-25 6.9.2-0 Dirk Lemstra <dirk#lem.....org>
Added -set colorspace:auto-grayscale=false that will prevent automatic conversion to grayscale inside coders that support grayscale.