CVBpy 15.0
cvb/ImagePixelAccess
1# CVBpy Example Script
2#
3# 1. Loads an image from file.
4# 2. Converts it to a numpy array without copying
5# 3. Modify pixel values through numpy
6# 4. Save the image.
7#
8# Requires: numpy
9
10import os
11import cvb
12
13image = cvb.Image(os.path.join(cvb.install_path(), "tutorial", "Clara.bmp"))
14
15# copy=Fasle is default, but just a request
16np_array = cvb.as_array(image, copy=False)
17
18if np_array.flags["OWNDATA"]:
19 raise RuntimeError("cannot map to numpy array")
20
21# pixel access
22print("Modifying pixel data via numpy array.")
23np_array[83 : 108, 48 : 157] = 0
24
25print("Saving: ./ClaraUnknown.bmp")
26image.save("ClaraUnknown.bmp")
27
The Common Vision Blox image.
Definition: __init__.py:2097
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:8318
numpy.array as_array(Any buffer, bool copy=False)
Maps a cvb object to a numpy array.
Definition: __init__.py:8068