Equivalent of python pywt(dwt2 API) in C++

256 views
Skip to first unread message

Dev

unread,
May 13, 2022, 12:52:28 AM5/13/22
to PyWavelets
Hi,

I am trying to port some work from python to C++ and as part of this, I encountered the "pywt.dwt2" python API . For this, I couldn't find the corresponding matching library or API in C++( while doing online search). So any help on this very much helpful.

Thanks in advance for doing this favor.

Thanks
Dev

Deepu

unread,
May 22, 2023, 2:22:49 AM5/22/23
to PyWavelets
In C++, you can use the OpenCV library to perform 2D discrete wavelet transform (DWT) and inverse DWT on images. OpenCV provides the functions `cv::dwt()` and `cv::idwt()` for this purpose.

Here's an example of how you can use OpenCV in C++ to perform 2D DWT and inverse DWT on an image:

```cpp
#include <opencv2/opencv.hpp>

int main()
{
    // Load the input image
    cv::Mat image = cv::imread("input_image.jpg", cv::IMREAD_GRAYSCALE);

    // Perform 2D DWT
    cv::Mat dwtImage;
    cv::dwt(image, dwtImage, cv::DCT_ROWS);

    // Perform inverse 2D DWT
    cv::Mat idwtImage;
    cv::idwt(dwtImage, idwtImage, cv::DCT_ROWS);

    // Display the original and reconstructed images
    cv::imshow("Original Image", image);
    cv::imshow("Reconstructed Image", idwtImage);
    cv::waitKey(0);

    return 0;
}
```

Please note that the above code assumes grayscale images, but you can modify it accordingly for color images. Additionally, you may need to install the OpenCV library and configure your C++ project to link against it.

Using OpenCV's DWT and IDWT functions, you can achieve similar functionality to `pywt.dwt2()` in Python.

I hope this helps you in porting your code to C++. If you have further questions, feel free to ask.

Ajay Dhakar

unread,
May 31, 2023, 1:48:05 AM5/31/23
to PyWavelets
Opencv doesn't have any function named as dwt or idwt.

Manoj Pandey

unread,
May 31, 2023, 1:23:14 PM5/31/23
to pywav...@googlegroups.com
Hello Ajay,

You should try dwt2 and idwt2.

--
You received this message because you are subscribed to the Google Groups "PyWavelets" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pywavelets+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pywavelets/60088fe8-f8e9-49ad-a4de-21f247dd07f7n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages