Giter Club home page Giter Club logo

Comments (5)

kyamagu avatar kyamagu commented on June 19, 2024

Very interesting. I'll add special treating for creating mxLOGICAL_CLASS array.

from mexopencv.

kyamagu avatar kyamagu commented on June 19, 2024

The last commit added thresholding to saturate all nonzero values to 1 in the conversion. Hope it fixes the issue.

from mexopencv.

amroamroamro avatar amroamroamro commented on June 19, 2024

while your commit solves the above case, cv::threshold has a couple of issues:

  • it only works with CV_8U, CV_16S, CV_32F types. Anything else throws an exception.
  • when converting from signed types, negative values get saturated at zero (false). Note that in MATLAB, logical(-1) == logical(1) == true, and only logical(0) == false

As far as I can tell, a better solution would be:

cv::compare(input, 0, input, cv::CMP_NE); // input = uint8( 255 * (input~=0) )
cv::min(input, 1, input);                 // input = min(input,1)

by comparing the matrix against scalar zero (result is of type CV_8UC1 set to 255 where nonzero), then using cv::min to cap at 1.


Here is a test to confirm (should return: [true,false,true] ie logical([1,0,1])):

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    double x[] = {-5.0, 0.0, 5.0};
    cv::Mat m(1, 3, CV_64FC1, (void*)x);
    plhs[0] = MxArray(m, mxLOGICAL_CLASS);
}

from mexopencv.

kyamagu avatar kyamagu commented on June 19, 2024

That makes sense. I have included the fix in the last commit, with a slight modification of the use of cv::setTo rather than cv::min.

Perhaps it's a TODO to prepare a unit test for MxArray.

from mexopencv.

amroamroamro avatar amroamroamro commented on June 19, 2024

thanks, that should do it. Unit-testing the MxArray layer sounds like a good idea..

from mexopencv.

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.