【发布时间】:2015-09-26 06:01:24
【问题描述】:
这是我的代码,我的“算法”正在尝试获取拜耳图像或 RGB 图像,并将通道 G(即亮度(甚至灰度))分离到颜色的不同通道中,
拜耳模式示例
void Utilities::SeparateChannels(int* channelR, int* channelG, int* channelB, double*& gr, double*& r, double*& b, double*& gb,int _width, int _height, int _colorOrder)
{
//swith case the color Order
int counter_R = 0;
int counter_GR = 0;
int counter_GB = 0;
int counter_B = 0;
switch (_colorOrder)
{
//grbg
case 0:
for (int j = 0; j < _width; j++)
{
for (int i = 0; i < _height; i++)
{
if (i % 2 == 0 && j % 2 == 0)
{
gr[counter_GR] = channelG[i*_width+ j];
counter_GR++;
}
else if (i % 2 == 0 && j % 2 == 1)
{
r[counter_R] = channelG[i*_width+ j];
counter_R++;
}
else if (i % 2 == 1 && j % 2 == 0)
{
b[counter_B] =channelG[i*_width+ j];
counter_B++;
}
else if (i % 2 == 1 && j % 2 == 1)
{
gb[counter_GB] = channelG[i*_width+ j];
counter_GB++;
}
}
}
我在 70 张图像上运行了分析器,并附上了我的结果。 你能推荐一种优化我的代码的方法吗?
【问题讨论】:
-
只是出于好奇,您使用了什么分析器?
-
你能解释一下代码吗?你是什么意思这里的单独频道?您显然只是在“阅读”绿色通道,并将其分成一些无法解释的 4 段输出。类型转换(int -> double)的目的是什么?
-
@Amit 我将一个数据通道分成几个通道
-
这根本不能回答问题。请使用算法的输入和所需输出的详细信息更新您的帖子。目前尚不清楚该算法实际上做了什么。类型不清楚,变量名称没有多大意义(我假设您正在处理标题所暗示的 RGB 像素)......如果不理解它就不可能“优化”算法。
-
您仍然没有回答为什么要进行类型转换。这绝对是一项成本高昂的操作。另外,您只使用channelG吗?那为什么其他通道都传入呢?
标签: c++ image-processing optimization