First, you can perform the same operation in IPLImage and use the built-in Mat constructor to convert it.
Secondly, your code seems too complicated since you are doing the same operation for all three dimensions. The following are more neat (in Mat notation):
unsigned char* data = (unsigned char*) img.data; for (int i = 0; i < image.cols * image.rows * image.channels(); ++i) { if (*data > 200) *data = 255; ++data; }
If you want the levels for the channels to be different, then:
unsigned char* data = (unsigned char*) img.data; assert(image.channels() == 3); for (int i = 0; i < image.cols * image.rows; ++i) { if (*data > 200) *data = 255; ++data; if (*data > 201) *data = 255; ++data; if (*data > 202) *data = 255; ++data; }
source share