在应用颜色时对图像应用阴影

我正在改变基于HSV 3滑块值的汽车的颜色。 我可以改变颜色,但它感觉像油漆。颜色变化后,图像没有创意。我可以如何应用阴影和效果。

我怎样才能应用在input图像的阴影和效果。

嗨,你可以参考下面的代码在C + +,在这里我只改变色调值,如果你想改变饱和度和价值只是创build一个与滑块位置值的垫,并加上或减去与适当的渠道(SAT或VAL)。

int H=50; Mat src, hsv, dst; char window_name[30] = "HSV Demo"; void HSV_Demo( int, void* ); int main( int argc, char** argv ){ src = imread( "car.jpg", 1 ); namedWindow( window_name, CV_WINDOW_AUTOSIZE ); createTrackbar( "Hue", window_name,&H, 179, HSV_Demo ); HSV_Demo( 0, 0 ); while(true) { int c; c = waitKey( 20 ); if( (char)c == 27 ) break; if( (char)c == 's' ) imwrite("result.jpg",dst); } } void HSV_Demo( int, void* ) { cvtColor(src, hsv,CV_BGR2HSV); Mat channel[3]; split(hsv,channel); channel[0].setTo(H); Mat tmp[3] = { channel[0],channel[1],channel[2] }; merge(tmp,3,dst); cvtColor(dst, dst,CV_HSV2BGR); imshow( window_name, dst ); } 

COLOR1COLOR2COLOR3Color4

编辑:-

基于下面的评论这里是使用HSV通过保持阴影创build黑白图像的步骤。

请注意,下面的方法并不完美,因为您可以看到边缘不规则,但您可以尝试类似下面的方法或改进下面的方法本身。

这个想法很简单,我们将考虑只有价值通道,并加上一些常数(滑块位置)创build白色和减去创build黑色,然后使用cvtColor()将其转换为BGR图像。 如果加法或减法结果出来,色调可能会消失。

在添加或减去之前,我们将通过分割色调(这里是红色)创build一个蒙版图像,并创build一个具有常量(滑块位置)和蒙版的新Mat,以便背景在加法或减法时保持不变。

 void HSV_Demo( int, void* ) { cvtColor(src, hsv,CV_BGR2HSV); Mat channel[3]; split(hsv,channel); Mat thr1,thr2; inRange(hsv,Scalar(165,50,50),Scalar(179,255,255), thr1); //Create mask to change to avoid background inRange(hsv,Scalar(0,50,50),Scalar(10,255,255), thr2); //Create mask to change to avoid background thr1=thr1+thr2; if(H>255){ if(H) H-=255; thr1.setTo(H,thr1); //Set the image to add to value which will create white color // channel[1].setTo(0); channel[2]=channel[2]+thr1; } else { H=255-H; thr1.setTo(H,thr1); // channel[1].setTo(0); channel[2]=channel[2]-thr1;//Set the image to subtract from value which will create black color } //Convert single channel to BGR Mat BGR; cvtColor(channel[2], BGR,CV_GRAY2BGR); imshow( window_name, BGR ); /* Mat tmp[3] = { channel[0],channel[1],channel[2] }; merge(tmp,3,dst); cvtColor(dst, dst,CV_HSV2BGR); imshow( window_name, dst );*/ } 

在上面的代码中,您将通过取消评论代码的注释来获得相同的结果。

结果:-
在这里输入图像说明在这里输入图像说明

在这里输入图像说明在这里输入图像说明