Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can easily solve this by reconstruct your image with alpha channel using the following step

  • Convert your source image to Gray scale.
  • Threshold the image to create alpha channel with complete transparency in black background region and zero transparency in foreground object region .
  • Split the original image in to three single channel.
  • Create the final result by merging three single channel and alpha(BGRA order).
  • Use the newly created image above your wall image.

And here is the C++ code for the above steps.

Mat src=imread("0.jpg",1);
Mat dst;//(src.rows,src.cols,CV_8UC4);
Mat tmp,alpha;

cvtColor(src,tmp,CV_BGR2GRAY);
threshold(tmp,alpha,100,255,THRESH_BINARY);

Mat rgb[3];
split(src,rgb);

Mat rgba[4]={rgb[0],rgb[1],rgb[2],alpha};
merge(rgba,4,dst);
imwrite("dst.png",dst);

Source Image without alpha.

image description

Result with alpha

image description

You can easily solve this by reconstruct your image with alpha channel using the following step

  • Convert your source image to Gray scale.
  • Threshold the image to create alpha channel with complete transparency in black background region and zero transparency in foreground object region .
  • Split the original image in to three single channel.
  • Create the final result by merging three single channel and alpha(BGRA order).
  • Use the newly created image above your wall image.

And here is the C++ code for the above steps.steps, re-write in Java as your need.

Mat src=imread("0.jpg",1);
Mat dst;//(src.rows,src.cols,CV_8UC4);
Mat tmp,alpha;

cvtColor(src,tmp,CV_BGR2GRAY);
threshold(tmp,alpha,100,255,THRESH_BINARY);

Mat rgb[3];
split(src,rgb);

Mat rgba[4]={rgb[0],rgb[1],rgb[2],alpha};
merge(rgba,4,dst);
imwrite("dst.png",dst);

Source Image without alpha.

image description

Result with alpha

image description