Search code examples
pythonscikit-image

Dimension decreases after performing "pyramid_reduce" function. How to fix?


I am trying to downscale the image using "scikit-image". However I cannot show the downscaled picture through matplotlib.imshow function because of the dimension. Is there a way to prevent such dimension reduction? I put the script as well.

import os, cv2, glob
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from skimage.transform import pyramid_reduce,
plt.style.use('dark_background')

img_path = os.path.join(img_base_path, value[0])
img = io.imread(img_path)
resized = pyramid_reduce(img, downscale=4)
print(resized.shape)

img.shape is (240, 240, 3). So what I expect for an output is (60, 60, 3). However what I get is (60, 60, 1).


Solution

  • When I read the documentation of the pyramid_reduce function, I notice the parameter multichannel:

    multichannel: bool,optional

    Whether the last axis of the image is to be interpreted as multiple channels or another spatial dimension.

    So I would suggest you to set that to True, otherwise he is treating your 2D color images as a 3D BW image:

    resized = pyramid_reduce(img, downscale=4, multichannel=True)