this is quite bad solution - convert the input/output image to color one in-place! Instead, the subsequent loop should be changed to handle both grayscale and color cases OR just add CV_Assert(_image->type() == CV_8UC3);