Repository: opencv
Issue: Problem for Simple Alpha Blending
Labels: bug,category: core,affected: 3.4,confirmed

<!--
If you have a question rather than reporting a bug please go to http://answers.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

Please:

* Read the documentation to test with the latest developer build.
* Check if other person has already created the same issue to avoid duplicates. You can comment on it if there already is an issue.
* Try to be as detailed as possible in your report.
* Report only one problem per created issue.


This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
<!-- Example
- OpenCV => 3.1
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2015
-->

- OpenCV => 4.2.0
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2019

##### Detailed description

<!-- your description -->

If running following the code for alpha blending, it output following results.  


```cpp
#include <opencv2/opencv.hpp>

int main( int argc, char* argv[] )
{
    // Read Image
    cv::Mat src = cv::imread( "lena.jpg" );

    // Alpha Blend with Blue, Green, and Red
    double alpha = 0.6;
    double beta  = 1.0 - alpha;
    cv::Mat blend_b = alpha * src + beta * cv::Scalar( 255, 0, 0 ); // Blue (issue case!)
    cv::Mat blend_g = alpha * src + beta * cv::Scalar( 0, 255, 0 ); // Green
    cv::Mat blend_r = alpha * src + beta * cv::Scalar( 0, 0, 255 ); // Red

    // Show Image
    cv::imshow( "src"  , src     );
    cv::imshow( "blue" , blend_b );
    cv::imshow( "green", blend_g );
    cv::imshow( "red"  , blend_r );
    cv::waitKey( 0 );

    return 0;
}
```

The output of alpha blending with green and red is correct result.  
These turned greenish color and reddish color.  
But, the output of alpha blending with blue has become whitish color.  
It is not expected output. It should turn to bluish color.  

![output1](https://user-images.githubusercontent.com/816705/74096280-35c03300-4b40-11ea-8ea6-4989ad36289e.png)

If changes blend color to the close to blue such as <code>cv::Scalar(255, 1, 0)</code> (just add one to green), it turn correctly to bluish color.

```cpp
cv::Mat blend_b = alpha * src + beta * cv::Scalar( 255, 1, 0 ); // Close to Blue
```
![output2](https://user-images.githubusercontent.com/816705/74096283-3bb61400-4b40-11ea-96a1-781d9e490c98.png)

##### Related issues

This seems to be related to this issue #14738.  
I think this is due to the difference between calculation results of cv::Mat and cv::MatExpr.  
Therefore, I know that this issue can be avoided by changing to following code.  

```patch
- cv::Mat blend_b = alpha * src + beta * cv::Scalar( 255, 0, 0 ); // Blue
+ cv::Mat blend_b = cv::Mat( alpha * src ) + beta * cv::Scalar( 255, 0, 0 ); // Blue
```

But, I think this is a bug of corner case. It should be fixed.
What do you think? Thanks,