Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Combine pyWavelet and openCV for image processing?

I need to do an image processing in python. i want to use wavelet transform as the filterbank. Can anyone suggest me which one library should i use? I had pywavelet installed, but i don't know how to combine it with opencv. If i use wavedec2 command, it raise ValueError("Expected 2D input data.")

Can anyone help me?

like image 927
rizkie Avatar asked Jul 02 '14 16:07

rizkie


People also ask

How do I combine images in OpenCV?

Use the concatenate() Function of NumPy to Combine Images in Python. We can read images using the imread() function of OpenCV and store them in a matrix. We can use the concatenate() function of NumPy to concatenate the matrices of the images along different axes.

Can OpenCV be used for image processing?

OpenCV is a pre-built, open-source CPU-only library (package) that is widely used for computer vision, machine learning, and image processing applications.

Why OpenCV is used for image processing?

Introduction. OpenCV is a great tool for image processing and performing computer vision tasks. It is an open-source library that can be used to perform tasks like face detection, objection tracking, landmark detection, and much more. It supports multiple languages including python, java C++.


1 Answers

Hope this helps

import numpy as np
import pywt
import cv2    

def w2d(img, mode='haar', level=1):
    imArray = cv2.imread(img)
    #Datatype conversions
    #convert to grayscale
    imArray = cv2.cvtColor( imArray,cv2.COLOR_RGB2GRAY )
    #convert to float
    imArray =  np.float32(imArray)   
    imArray /= 255;
    # compute coefficients 
    coeffs=pywt.wavedec2(imArray, mode, level=level)

    #Process Coefficients
    coeffs_H=list(coeffs)  
    coeffs_H[0] *= 0;  

    # reconstruction
    imArray_H=pywt.waverec2(coeffs_H, mode);
    imArray_H *= 255;
    imArray_H =  np.uint8(imArray_H)
    #Display result
    cv2.imshow('image',imArray_H)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

w2d("test1.png",'db1',10)
like image 181
Navaneeth Avatar answered Sep 17 '22 20:09

Navaneeth