简体   繁体   English

使用存储在C数组中的像素值反转灰度图像

[英]Inverting a gray scale image with the pixel values stored in an array in C

I currently am doing homework and I have this question that I am unable to understand. 我目前正在做作业,我有一个我无法理解的问题。 I am NOT asking for someone to code for me or anything, I just find that I am unable to understand what my question is asking for. 不是要别人为我或任何东西编码,我只是发现我无法理解我的问题的要求。 If someone can help me understand what should be done, then I can code it ;p! 如果有人可以帮助我理解应该做什么,那么我可以编写代码; p!

Here is the question: 这是问题:

Invert the image intensities, so that black becomes white and vice versa, and light shades of grey become the corresponding dark shade. 反转图像强度,以使黑色变为白色,反之亦然,而灰色的浅色变为相应的深色。

Now, I know that white is 0 and black is 255 and all I have to do is swap them in the array, but what does it mean in the last part where it asks me to switch the light shades of grey to dark shades of grey. 现在,我知道白色是0,黑色是255,我所要做的就是在数组中交换它们,但是在最后一部分中,它要求我将灰色的浅色转换为灰色的深色是什么意思? 。 Assuming it is referring to the remaining 1-254 numbers (pixels), what am I supposed to swap? 假设它是指剩余的1-254数字(像素),我应该交换什么? If someone can explain to me how to do this then it would be great. 如果有人可以向我解释该如何做,那就太好了。 Again, I am not looking for someone to code for me, I just want to know what it is asking for so I can myself code it. 再说一次,我不是要找人为我编写代码,我只是想知道它的要求是什么,所以我自己可以编写代码。

The homework does not even mention the word "swap" so forget all about it. 作业甚至都没有提到“交换”一词,所以就不用理会了。 It clearly states that the grayscale should be inverted. 它明确指出应反转灰度。

This is how you would do it for the first pixel: 这是您要对第一个像素执行的操作:

image[0] = 255 - image[0];

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

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