【发布时间】:2019-07-10 15:21:22
【问题描述】:
我正在尝试将 png 颜色表应用于图像,但无法将 png 中的像素与目标图像匹配。
颜色表是 64^3 的 png
据我了解,大图像中的每个像素,都需要在颜色表中使用相似的值。这似乎将颜色限制为 262144 = 64 x 64 x 64。但我不确定这是我得到的效果,结果是完全黑色的图像,这意味着没有价值,或者看起来很奇怪的颜色。
这是我的代码
// The table is 64 x 64 x 64
float size = 64.0;
// This is the original image
// This function returns a pixel value inside a 3d space
// and the `rgb` method will return a vector with the rgb values
vec3 source_image = sample(src_i, samplerCoord(src_i)).rgb;
// Here I take the pixel value of the image for the red channel
// and multiply it by 64.0, then divide by 255.0 for the 8-bit image
float x = floor(floor(source_image.r * size)/255.0);
// The same thing for the green value on the y axis
float y = floor(floor(source_image.g * size)/255.0);
// Match a value from the image in the color table
vec3 color = sample(src_l, vec2(x, y)).rgb;
src_i.r = color.r;
src_i.g = color.g;
// The blue should be on the z axis, or the nth tile, so I think for this
// case it will be easier to convert the color table to one long row
src_i.b = floor(floor(source_image.b * size)/255.0);
// The image is black
原图
预期结果
如果我乘以 255(这似乎是正确的),那么我会得到这个结果
float x = floor(source_image.r * 255.0);
float y = floor(source_image.g * 255.0);
如果您能指出数学有什么问题,我将不胜感激
【问题讨论】:
-
是像素值,我会编辑这部分。感谢您添加照片
标签: opengl image-processing glsl core-image