What is the minimal difference in RGB color values which Mathematica renders and exports as different colors?

笑着哭i 提交于 2020-02-02 03:57:05

问题


I was amazed when I found that Mathematica gives True for the following code (on 32 bit Windows XP with Mathematica 8.0.1):

Rasterize[Graphics[{RGBColor[0, 0, 0], Disk[]}]] === 
 Rasterize[Graphics[{RGBColor[0, 0, 1/257], Disk[]}]]

What is the minimal difference in RGB color values which Mathematica renders and exports as different colors? Is it machine-dependent?


回答1:


I believe this behaviour is machine dependent, but I do not know how exactly it depends on the OS. On my machine, it evaluates to True only when the denominator is 511.

n = 257; 
While[(Rasterize[Graphics[{RGBColor[0, 0, 0], Disk[]}]] === 
    Rasterize[Graphics[{RGBColor[0, 0, 1/n], Disk[]}]]) != True, 
 n++]; 
Print@n

Out[1]=511

There is a difference between the two images for n<511

p1 = ImageData@Rasterize[Graphics[{RGBColor[0, 0, 0], Disk[]}]];
p2 = ImageData@Rasterize[Graphics[{RGBColor[0, 0, 1/257], Disk[]}]];
ArrayPlot[p1 - p2]

This difference is constant all the way through n=510 and is equal to 1/255.

Max[p2 - p1] === N[1/255]
Out[1]=True



回答2:


Looks like Rasterize rounds each pixel's R G B channels to the closest 8bit value (to the closest 1/256).

image = Image[{{{0, 0, .2/256}, {0, 0, .7/256}, {0, 0, 1.2/256}, {0, 
     0, 1.7/256}}}, ImageSize -> 4]
ImageData@image
Rasterize@image
ImageData@Rasterize@image

So the minimal difference, rasterizing into different colors should be around 0.000000000000000000000000000...




回答3:


Guilty party here is Rasterize, which chops off color precision. Get help on ImageType[] to see that Mathematica actually recognizes other bit depths, but Rasterize[] vandalizes anything beyond Byte.



来源:https://stackoverflow.com/questions/7780327/what-is-the-minimal-difference-in-rgb-color-values-which-mathematica-renders-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!