I have an image represented in an array such that its shape is (128,128) and the data type is bool (which means it represents a binary image).
So I need to resize it to a given scale (say, (543, 347)).
Can anyone tell me a way to do this easily using python's scikit-image library?
You could use resize and img_as_bool to get the job done.
import numpy as np
from skimage import io
from skimage.transform import resize
from skimage import img_as_bool
import matplotlib.pyplot as plt
bool_arr = np.zeros(shape=(128, 128), dtype=np.bool)
bool_arr[32:96, 32:96] = True
resized = img_as_bool(resize(bool_arr, (543, 347)))
fig, (ax0, ax1) = plt.subplots(1, 2)
ax0.imshow(bool_arr, cmap='gray')
ax0.set_title('Boolean array')
ax1.imshow(resized, cmap='gray')
ax1.set_title('Resized')
plt.show(fig)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With