Formatting CIColorCube data

时光总嘲笑我的痴心妄想 提交于 2019-11-29 11:29:49

The accepted answer is incorrect. While the cube data is indeed supposed to be scaled to [0 .. 1], it's supposed to be float, not int.

float color_cube_data[8*4] = { 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };

(Technically, you don't have to put the ".0" on each number, the compiler knows how to handle it.)

iosfreak

I found the issue... I have updated my question if anyone has the same problem!

The input float array had to be pre-divided out of 255.

The original used 255:

uint8_t color_cube_data[8*4] = {
    0, 0, 0, 1,
    255, 0, 0, 1,
    0, 255, 0, 1,
    255, 255, 0, 1,
    0, 0, 255, 1,
    255, 0, 255, 1,
    0, 255, 255, 1,
    255, 255, 255, 1
};

It should look like this instead:

uint8_t color_cube_data[8*4] = {
    0, 0, 0, 1,
    1, 0, 0, 1,
    0, 1, 0, 1,
    1, 1, 0, 1,
    0, 0, 1, 1,
    1, 0, 1, 1,
    0, 1, 1, 1,
    1, 1, 1, 1
};

Your problem is that you are using value 1(which is next to zero) for alpha channel, max for uint8_t is 255

See example below:

CIFilter *cubeHeatmapLookupFilter = [CIFilter filterWithName:@"CIColorCube"];

int dimension = 4;  // Must be power of 2, max of 128
int cubeDataSize = 4 * dimension * dimension * dimension;

unsigned char cubeDataBytes[cubeDataSize];

//cubeDataBytes[cubeDataSize]
unsigned char cubeDataBytes[4*4*4*4] = {
    0,      0,      0,      0,
    255,    0,      0,      170,
    255,    250,    0,      200,
    255,    255,    255,    255
};

NSData *cube_data = [NSData dataWithBytes:cubeDataBytes length:(cubeDataSize*sizeof(char))];

//applying
[cubeHeatmapLookupFilter setValue:myImage forKey:@"inputImage"];
[cubeHeatmapLookupFilter setValue:cube_data forKey:@"inputCubeData"];
[cubeHeatmapLookupFilter setValue:@(dimension) forKey:@"inputCubeDimension"];

This is link to full project https://github.com/knerush/heatMap

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