Giter Club home page Giter Club logo

Comments (3)

Kumataro avatar Kumataro commented on June 19, 2024

Maybe duplicated #25165

from opencv.

Kumataro avatar Kumataro commented on June 19, 2024

Umm, I read again. This behavious has been changed after 4.9.0, but I think OpenCV 4.9.0 behavious is correct

( More precisely, the case where src2 is Scalar is not described in the multiply function... )

  1. When using an integer as the multiplier, versions 4.5 to 4.8 only the blue channel is correctly multiplied by 2.0, while the green and red channels' pixel values become zero.
  2. When using a one-dimensional NumPy array (np.array([2.0])) as the multiplier, versions 4.5 to 4.8 correctly multiply all channels (BGR) of the image by the given value. However, in OpenCV 4.9, only the blue channel is correctly multiplied, while the green and red channels' pixel values are set to zero.

Please could you see atirhmertric function behavious at https://docs.opencv.org/4.9.0/d2/de8/group__core__array.html#ga10ac1bfb180e2cfda1701d06c24fdbd6 ?

  • Precondition : src1(I) = [50, 50, 50]
  • Try to execute : dst = multiply( src1 , src2).
  • If src2 = 2 then dst = [50x2, 50x2, 50x2] = [100, 100, 100]
  • If src2 = [2,3,4] then dst = [50x2, 50x3, 50x4] = [100, 150, 200]
  • If src2 = [2] then dst = [50x2, 50x0, 50x0] = [100, 0, 0]

From https://docs.opencv.org/4.9.0/d2/de8/group__core__array.html#ga979d898a58d7f61c53003e162e7ad89f

Note
Saturation is not applied when the output array has the depth CV_32S. You may even get result of an incorrect sign in the case of overflow.
(Python) Be careful to difference behaviour between src1/src2 are single number and they are tuple/array. multiply(src,X) means multiply(src,(X,X,X,X)). multiply(src,(X,)) means multiply(src,(X,0,0,0)).

And This behavious is same as C++

#include <iostream>
#include <opencv2/core.hpp>

int main(void)
{
  cv::Mat gray_img(400,400,CV_8UC3, cv::Scalar::all(50));
  cv::Mat tmp_img_int;
  cv::multiply(gray_img, 2, tmp_img_int);
  std::cout << "INT = " << cv::format(tmp_img_int(cv::Rect(0,0,2,2)), cv::Formatter::FMT_NUMPY) << std::endl;

  cv::Mat tmp_img_scalar;
  cv::multiply(gray_img, cv::Scalar(2), tmp_img_scalar);
  std::cout << "SCALAR = " << cv::format(tmp_img_scalar(cv::Rect(0,0,2,2)), cv::Formatter::FMT_NUMPY) << std::endl;
  return 0;
}

Result

$ make && ./a.out
g++ main.cpp -o a.out \
        -I/usr/local/include/opencv4 \
        -lopencv_core
INT = array([[[100, 100, 100], [100, 100, 100]],
       [[100, 100, 100], [100, 100, 100]]], dtype='uint8')
SCALAR = array([[[100,   0,   0], [100,   0,   0]],
       [[100,   0,   0], [100,   0,   0]]], dtype='uint8')

from opencv.

Kumataro avatar Kumataro commented on June 19, 2024

@cocositu If OK, please could you close this issue ?

from opencv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.