Handling both 16bit and 8bit images in the same program.
Hello, here's my problem. I'm writing a program that shall handle both 8bit and 16 bit data. The problem is that every procedure to modify the data must use the template of the proper class. For example:
img = cv::imread(path, CV_LOAD_IMAGE_ANYDEPTH);
std::for_each(img.begin<?>(), img.end<?>(), cleanPixel);
? above being ushort in the case of 16bit and uchar in the case of 8bit data. I know that I can check the depth of the image using the method img.depth(), and check the equality with either CV_16U or CV_8U. Is that the only way? I was also thinking to use some preprocessor constant, and maybe compile two different version of the program (one only for 8bit images and one only for 16bit images).
Thanks in advance for your help.
what do you want to do exactly ?
I want, if possible, avoid ifs every time I have to access the pixel data.
What does it mean img.begin ?
It's an iterator. Very useful things. In short, every time you do iterator++, it points at the next pixel, and *iterator gives you a reference to the pixel it points to. They're available in just about every STL or boost data type.
@Tetragramm I didn't know iterator method begin in class Mat. Thanks. Never mind I don't think I will use it.
What is cleanPixel ?
The last parameter of std::for_each is the function you want to apply to each element of the range. So in this case it's their own function, which does... something.
Yes I understand that "own function, which does... something." but I don't think @mmecchia need foreach to rewrite method like setTo , exp or 2 x+1...