Ask Your Question

Revision history [back]

No idea how to get 3 my answer is :

[0.02, 0.0020000001, 0.00019999999]
[50, 499.99997, 5000]
[0, 23.181816, 254.99998]

with this code

class InverseMat {
    float *pData;
public:
    InverseMat(float *p) { pData = p; };
    void operator ()(float &pixel, const int * position) const {
        pixel = 1/pixel;
    }
};

int main(int argc, char* argv[])
{
    Mat imgTest = (Mat_<float>(1, 3) << 0.02,0.002,0.0002);
    cout << imgTest << "\n";
    imgTest.forEach<float>(InverseMat(imgTest.ptr<float>(0)));
    cout << imgTest << "\n";
    Mat dstTest;
    normalize(imgTest, dstTest, 255, 0, NORM_MINMAX);
    cout << dstTest << "\n";

    return 0;
}

No idea how to get 3 my as minimum. My answer is :

[0.02, 0.0020000001, 0.00019999999]
[50, 499.99997, 5000]
[0, 23.181816, 254.99998]

with this code

class InverseMat {
    float *pData;
public:
    InverseMat(float *p) { pData = p; };
    void operator ()(float &pixel, const int * position) const {
        pixel = 1/pixel;
    }
};

int main(int argc, char* argv[])
{
    Mat imgTest = (Mat_<float>(1, 3) << 0.02,0.002,0.0002);
    cout << imgTest << "\n";
    imgTest.forEach<float>(InverseMat(imgTest.ptr<float>(0)));
    cout << imgTest << "\n";
    Mat dstTest;
    normalize(imgTest, dstTest, 255, 0, NORM_MINMAX);
    cout << dstTest << "\n";

    return 0;
}

No idea how to get 3 as minimum. My answer is :

[0.02, 0.0020000001, 0.00019999999]
[50, 499.99997, 5000]
[0, 23.181816, 254.99998]

with this code

class InverseMat {
    float *pData;
public:
    InverseMat(float *p) { pData = p; };
    void operator ()(float &pixel, const int * position) const {
        pixel = 1/pixel;
    }
};

int main(int argc, char* argv[])
{
    Mat imgTest = (Mat_<float>(1, 3) << 0.02,0.002,0.0002);
    cout << imgTest << "\n";
    imgTest.forEach<float>(InverseMat(imgTest.ptr<float>(0)));
imgTest.forEach<float>([](float &p, const int * /*position*/) -> void {

        p = 1/p;
    });
    cout << imgTest << "\n";
    Mat dstTest;
    normalize(imgTest, dstTest, 255, 0, NORM_MINMAX);
    cout << dstTest << "\n";

    return 0;
}

No idea how to get 3 as minimum. My answer is :

[0.02, 0.0020000001, 0.00019999999]
[50, 499.99997, 5000]
[0, 23.181816, 254.99998]

with this code

int main(int argc, char* argv[])
{
    Mat imgTest = (Mat_<float>(1, 3) << 0.02,0.002,0.0002);
    cout << imgTest << "\n";
    imgTest.forEach<float>([](float &p, const int * /*position*/) -> void {

        p = 1/p;
    });
    cout << imgTest << "\n";
    Mat dstTest;
    normalize(imgTest, dstTest, 255, 0, NORM_MINMAX);
    cout << dstTest << "\n";

    return 0;
}

I think you can create a vector of indices of a sorted vector too

No idea how to get 3 as minimum. My answer is :

[0.02, 0.0020000001, 0.00019999999]
[50, 499.99997, 5000]
[0, 23.181816, 254.99998]

with this code

int main(int argc, char* argv[])
{
    Mat imgTest = (Mat_<float>(1, 3) << 0.02,0.002,0.0002);
    cout << imgTest << "\n";
    imgTest.forEach<float>([](float &p, const int * /*position*/) -> void {

        p = 1/p;
    });
    cout << imgTest << "\n";
    Mat dstTest;
    normalize(imgTest, dstTest, 255, 0, NORM_MINMAX);
    cout << dstTest << "\n";

    return 0;
}

I think you can create a vector of indices of a sorted vector too

Mat imgTest = (Mat_<float>(2,3) << 0.0002,0.02,0.00250,0.0005,.002,0.01);
normalize(imgTest, imgTest, 255, 0, NORM_MINMAX);

std::vector<int> y(static_cast<int>(imgTest.total()));
std::size_t n(0);
std::generate(std::begin(y), std::end(y), [&] { return n++; });
if (imgTest.isContinuous())
    std::sort(std::begin(y),
        std::end(y),
        [&](int i1, int i2) { return imgTest.ptr<float>(0)[i1] < imgTest.ptr<float>(0)[i2]; });
else
{
    cout << "cannot do that";
    return 0;
}

Mat dstTest(imgTest.size(),imgTest.type());
for (int i = 0; i < imgTest.total(); i++)
    dstTest.ptr<float>(0)[i] = imgTest.ptr<float>(0)[y[i]];

cout << dstTest << "\n";

https://stackoverflow.com/questions/25921706/creating-a-vector-of-indices-of-a-sorted-vector