pythonwaveletpywavelets

How to read an image with PyWavelets?


I need to use pyWavelet,i.e. pywt to read my image to make wavelets for it, the example below used to load camera image only, how to use another image from my computer path?

import pywt
import pywt.data

# Load image
original = pywt.data.camera()

Solution

  • I'm not sure if you can read in an image just using pywt but you can load in a image using OpenCV and then convert it to a usable format for use with pywt

    import cv2
    import numpy as np
    import pywt
    
    image = cv2.imread('1.png')
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    
    # Convert to float for more resolution for use with pywt
    image = np.float32(image)
    image /= 255
    
    # ...
    # Do your processing
    # ...
    
    # Convert back to uint8 OpenCV format
    image *= 255
    image = np.uint8(image)
    
    cv2.imshow('image', image)
    cv2.waitKey(0)