Ask Your Question

Bend overlay image to the curvature of underlay image using displacement map filter

asked 2018-02-22 09:39:37 -0600

Udaib khan gravatar image

updated 2020-10-24 02:16:30 -0600

I want to place one image on another image such that it looks realistic suppose i have two images one is logo image and other is shirt image, now i want to place logo over shirt image such that logo adjust to curves and depth of shirt image. Please suggest me links or any source that could help me . thanks current i am using simple placement using image overlay transparency and addWeight Api with region of interest i am adding alpha value to logo image Any suggestions or code snippet would be appreciated.

public void loadLogo(ActionEvent actionEvent) throws IOException, InterruptedException 

            Mat imageROI, croppedImage;
            Rect roi;
            FileChooser fileChooser = new FileChooser();
            File selectedFile = fileChooser.showOpenDialog(null);
            if (selectedFile != null) 
                BufferedImage logoImage =;
                Image logo = logoImage;
                Mat backgroundImageMatrics = createMat(img);
                Mat logoImageMatrics = createMat(logoImage);
                roi = new Rect(100, 200, logoImageMatrics.cols(), logoImageMatrics.rows());
                imageROI = backgroundImageMatrics.submat(roi);
                HighGui.imshow("Linear Blend", backgroundImageMatrics);


Here below is what actually i want to achieve

This is required result image description image description

edit retag flag offensive close merge delete


LBerger gravatar imageLBerger ( 2018-02-22 10:14:04 -0600 )edit

opencv, being a computer-vision library, does not have any support for alpha blending.

i think, you're (ab)using the wrong lib here.

berak gravatar imageberak ( 2018-02-23 04:47:36 -0600 )edit

@berak there is support for alpha blending in opencv please see opencv documentation and here i am attaching link , please go through documentation Opencv alpha blending

Udaib khan gravatar imageUdaib khan ( 2018-02-23 08:08:38 -0600 )edit

^^ that's linear blending, not alpha. and it's about using addWeighted(), again.

berak gravatar imageberak ( 2018-02-23 08:47:29 -0600 )edit

ok @break tell me how to achieve the bending of logo on uneven surface i have tried addweight() but its not giving required result, see above images you will get my point

Udaib khan gravatar imageUdaib khan ( 2018-02-23 09:36:00 -0600 )edit

there's remap(), but imho, what you want is impossible with opencv means. maybe you'll have to look into opengl for this, it would allow you to warp things in 3d, also proper alpha based ops.

berak gravatar imageberak ( 2018-03-01 08:06:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-02-22 10:13:22 -0600

vps gravatar image

use addWeighted(Roi, 0.3, image, 1 - 0.3, 0, image) function.

edit flag offensive delete link more


@vps i have applied it but its not producing the required result please see the required image now it only overlay image not adjusting to uneven surface of shirt

Udaib khan gravatar imageUdaib khan ( 2018-02-23 04:19:13 -0600 )edit

@Udaib khan ...Hi, I am not sure that logo will adjust as per the surface of the shirt. It is 2D image.

vps gravatar imagevps ( 2018-03-01 07:33:52 -0600 )edit

@vps so how to achieve it in java opencv, i think it's texture bump mapping? i dont want to goto 3D world , please suggest me method or techniques so that i can achieve it in 2D way as i have all my images in 2D

Udaib khan gravatar imageUdaib khan ( 2018-03-01 07:37:19 -0600 )edit

@ hi, sorry, I don't have experience in this. Hope, Some expert will help you.

vps gravatar imagevps ( 2018-03-01 07:44:13 -0600 )edit

Question Tools

1 follower


Asked: 2018-02-22 09:31:31 -0600

Seen: 1,053 times

Last updated: Mar 05 '18