for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
if (dim == 3) {
Vec3b pixel = src.at<Vec3b>(row, col);
int blue = pixel[0];
int green = pixel[1];
int red = pixel[2];
src.at<Vec3b>(row, col)[0] = 255 - blue;
src.at<Vec3b>(row, col)[1] = 255 - green;
src.at<Vec3b>(row, col)[2] = 255 - red;
}
if (dim == 1) {
int pv = src.at<uchar>(row, col);
src.at<uchar>(row, col) = (255 - pv);
}
}
}