ale*_*cci 4 algorithm bit-manipulation bit-shift conditional-statements
我正在编写一个图像二值化算法,它只是将每个像素的亮度值(灰度图像)转换为黑色或白色.目前,用于二值化每个像素的算法大致是这样的
if( grayscale[x] < thresholdValue)
{
bitonal[x] = 1;
}
Run Code Online (Sandbox Code Playgroud)
(这实际上是ACTUAL算法的简化,因为双色调图像实际上是一个bitpacked图像(每个数组索引保持8个像素)所以我实际上在当前数组索引中对1进行bitpack ...但我不认为这会改变我的题.
我试图做的是删除if语句的需要.
我在想的是按照这个方法做点什么.通过灰度减去thresholdValue,然后执行一些位操作技巧以清除或移位位,如果结果为(grayscale[x]-threshold) is less than 0, I get a 0. otherwise I would get a 1
.如果它更容易做到(if grayscale[x]-threshold < 0 + bitwise trickery get a 1, else get a 0)
反过来也可以工作......只要我可以摆脱分支声明...任何帮助赞赏..