简体   繁体   English

反转c中的图像强度

[英]Inverting image intensities in c

void invert( uint8_t array[], 
         unsigned int cols, 
         unsigned int rows )
{
    int y;
    uint8_t darkest = 255;
    uint8_t lightest = 0;
    uint8_t anygray = y;
    for (int x = 0; x < (cols*rows); x++)
    {
        for (y = 0; y < (cols*rows); y++)
        {
            if (array[x] == darkest && array[x] == anygray && array[x] == lightest)
            {
                array[x] = 255-y;
            }
        }
    }
}

I have a function here that inverts the image intensities, so that black becomes white, and vice versa as well as all the light grays become dark grays. 我这里有一个函数可以反转图像强度,使黑色变为白色,反之亦然,所有浅灰色也变为深灰色。 But my code here doesn't seem to work and I don't know where i went wrong. 但是我的代码在这里似乎不起作用,我也不知道我哪里出错了。 Would anybody be able to help me out? 有人可以帮我吗?

I haven't prototyped anything to check but I see at least two things that look suspicious. 我没有原型来检查任何东西,但我至少看到了两点看起来可疑的东西。

1) I expected the && in the IF to be ||. 1)我期望IF中的&&为||。

2) I expected array[x] = 255 - y to be something like array[x] = 255 - array[x]. 2)我期望array [x] = 255-y类似于array [x] = 255-array [x]。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM