在OSX中无法可靠地设置tiff()分辨率和压缩 [英] tiff() resolution and compression are not reliably set in OSX

查看:166
本文介绍了在OSX中无法可靠地设置tiff()分辨率和压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统上似乎忽略了 tiff()中的分辨率和压缩选项(请参阅下面的信息)。这似乎与)。



所以我安装了它,再次运行此示例代码,但这次将类型设置为cairo。这是我之后从ImageMagick获得的:

  $ identify -verbose /Users/schaunw/Desktop/example.tiff 
图像:/Users/schaunw/Desktop/example.tiff
格式:TIFF(标记图像文件格式)
类:DirectClass
几何:1000x600 + 0 + 0
分辨率: 200x200
打印尺寸:5x3
单位:PixelsPerInch
类型:灰度
Endianess:MSB
颜色空间:灰色
深度:8位
页面几何:1000x600 + 0 + 0
Dispose:Undefined
迭代次数:0
压缩:LZW
方向:TopLeft
文件大小:19.8KB
数字像素:600K

注意适当的小文件大小和LZW压缩,但也注意到这次ImageMagick明确说明打印尺寸为5x3。它之前没有这样做。



所以看起来你的问题与OS X不再与X11一起发货了。安装X11应该可以解决您的问题。


The resolution and compression options in tiff() seem to be ignored on my system (see information below). This appears to be the same problem discussed in this SO question; I'm posting the question here so that I can be more specific about my system.

For instance the following code,

x <- rnorm(1000)
tiff("example.tiff", height=3, width=5, units="in", res=200, compression="lzw")
hist(x)
dev.off()

yields a .tiff file that superficially looks fine, but when I use Photoshop to look at the image size, I see this

This is consistent with tiff() creating a file with the right number of pixels, but the wrong size in inches. (This discrepancy gets me into trouble when I want to control both the font size and the image size of an image, for instance for publications that require specific physical image sizes).

Note that the file is also 2.5 MB, which seems too big for a 3"-by-5" black-and-white lzw-compressed tiff. I suspect that the compression option is also being ignored.

I get the same result with ggsave (which might rely on tiff() under the hood?) and with png(), so this seems to be a general problem with the way R and OSX deal with image files.

I'm using R Studio 0.97.449, with R 3.0.0 on OSX 10.8 as detailed below.

> sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.0.0

解决方案

I'm on the same version of R and OS X that you are. When I run your example and then call up the image details using ImageMagick, I see the following (redacted) in my console:

$ identify -verbose /Users/schaunw/Desktop/example.tiff
Image: /Users/schaunw/Desktop/example.tiff
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 1000x600+0+0
Units: PixelsPerInch
Type: GrayscaleAlpha
Endianess: MSB
Colorspace: Gray
Depth: 8-bit
Page geometry: 1000x600+0+0
Dispose: Undefined
Iterations: 0
Compression: None
Orientation: TopLeft
Filesize: 2.402MB
Number pixels: 600K

The file size, as you point out, if quite large for an image supposedly that small, and it's showing a lack of compression. The answer to that problem revealed itself when I tried to change the type argument in the tiff function: OS X told me it no longer supports X11, and that I would need to install it manually if I wanted to use it (see http://www.macrumors.com/2012/02/17/apple-removes-x11-in-os-x-mountain-lion-shifts-support-to-open-source-xquartz/).

So I installed it, and ran this your example code again, but this time with type set to "cairo". This is what I got from ImageMagick afterwards:

$ identify -verbose /Users/schaunw/Desktop/example.tiff
Image: /Users/schaunw/Desktop/example.tiff
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 1000x600+0+0
Resolution: 200x200
Print size: 5x3
Units: PixelsPerInch
Type: Grayscale
Endianess: MSB
Colorspace: Gray
Depth: 8-bit
Page geometry: 1000x600+0+0
Dispose: Undefined
Iterations: 0
Compression: LZW
Orientation: TopLeft
Filesize: 19.8KB
Number pixels: 600K

Notice the appropriately small file size and the LZW compression, but also notice that this time ImageMagick explicitly states that the print size is 5x3. It didn't do that before.

So it looks like your problem has to do with OS X no longer shipping with X11. Installing X11 should fix your problem.

这篇关于在OSX中无法可靠地设置tiff()分辨率和压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆