Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize a binary image through scikit-image?

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?

like image 932
Vajira Prabuddhaka Avatar asked Jul 08 '26 19:07

Vajira Prabuddhaka


1 Answers

You could use resize and img_as_bool to get the job done.

Demo

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)

results

like image 147
Tonechas Avatar answered Jul 11 '26 10:07

Tonechas



Donate For Us

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