Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "greater than" not working with char type?

Tags:

c++

I am implementing an image processing filter within OTB (a C++ library).

I got a strange behaviour with some very basic testing. When I read my image as "char", the following code always outputs the pixel value (in the 0-200 range) even if it is larger than 150. However, it works fine when I use "short int". Is there a special behaviour with "char" (like a letter comparison instead of its numerical value) or could there be any other reason ?

Of course, my image pixels are stored in Bytes, so I prefer to handle "char" instead of "int" because the image is quite large (> 10 Gb).

if (pixelvalue > 150)
{
out = 255;
}
else
{
out = pixelvalue;
}
like image 569
radouxju Avatar asked Dec 05 '22 01:12

radouxju


1 Answers

unsigned char runs to (at least) 255, but char may be signed and limited to 127.

like image 156
MSalters Avatar answered Dec 06 '22 14:12

MSalters