@@ -101,22 +101,35 @@ def __init__(
101101 :type binary: bool, optional
102102 :raises TypeError: unknown type passed to constructor
103103
104- Create a new image instance which contains pixel values as well as
105- information about image size, datatype, color planes and domain.
104+ Create a new :class:`Image` instance which contains pixel values as well as
105+ information about image size, datatype, color planes and domain. The pixel
106+ data is stored in a NumPy array, encapsulated by the object.
106107
107- The ``image`` can be specified in several ways:
108+ An image is considered to be a two-dimensional (width x height) grid of pixel
109+ values, that lie within one or more "color" planes.
110+
111+ The image data can be specified by:
112+
113+ - a NumPy 2D or 3D array for a greyscale or color image respectively. For
114+ the latter case, the last index represents the color plane::
115+
116+ Image(nd.zeros((100, 200)))
117+ Image(nd.zeros((100, 200, 4)), colororder="WXYZ")
108118
109- - as an :class:`Image` instance and its pixel array will be *referenced*
110- by the new :class:`Image`.
111- - an a NumPy 2D or 3D array for a greyscale or color image respectively.
112119 - a lists of lists of pixel values, each inner list must have the same
113120 number of elements (columns)::
114121
115122 Image([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
116123
124+ - a range of class methods that serve as constructors for common image types such as
125+ :meth:`Zeros`, :meth:`Constant`, :meth:`Random` and :meth:`String`, or
126+ read an image from a file :meth:`Read`.
127+
128+ - an existing :class:`Image` instance.
129+
117130 **Pixel datatype**
118131
119- The ``dtype`` of an image comes from the internal NumPy pixel array.
132+ The ``dtype`` of an image comes from the encapsulated NumPy pixel array.
120133 If ``image`` is an :class:`Image` instance or NumPy ndarray then its dtype is
121134 determined by the NumPy ndarray.
122135
@@ -127,31 +140,43 @@ def __init__(
127140 - the smallest signed or unsigned int that can represent its
128141 value span.
129142
130- An `` image`` can have bool values. When used in a numerical expression
131- its values will bs cast to numeric values of 0 or 1 representing
143+ An image can have boolean pixel values. When used in a numerical expression,
144+ its values will be cast to integer values of 0 or 1 representing
132145 False and True respectively.
133146
134147 **Color planes**
135148
136149 Images can have multiple planes, typically three (representing the
137- primary colors red, green and blue) but any number is possible. In
138- the underlying Numpy array these planes are identified by an integer
139- plane index (the last dimension of the 3D array). The :class:`Image`
140- contains a dictionary that maps the name of a color plane to its
141- index value. The color plane order can be specified as a dict or
142- a string.
150+ primary colors red, green and blue) but *any number* is possible. In
151+ the underlying Numpy array, these planes are identified by an integer
152+ plane index (the last dimension of the 3D array).
153+
154+ Rather than rely on a limiting convention such as planes being in the order
155+ RGB or BGR, the :class:`Image` contains a dictionary that maps the name of a color plane to
156+ its index value. The color plane order can be specified as a dict or a string, eg::
157+
158+ Image(img, colororder="RGB")
159+ Image(img, colororder="red:green:blue:alpha")
160+ Image(img, colororder=dict("R"=2, "G"=1, "B"=0))
161+
162+ Image planes can be referenced by their index or by their name, eg.::
163+
164+ img.plane(0)
165+ img.plane("alpha")
166+
167+ :seealso: :meth:`colororder` :meth:`colororder_str`
143168
144169 **Image domain**
145170
146- An :class:`Image` has a width and height in units of pixesl , but for
171+ An :class:`Image` has a width and height in units of pixels , but for
147172 some applications it is useful to specify the pixel coordinates in other
148- units, perhaps metres, or latitude/longitude, or for a spherical image
149- as azimuth and colatitude. The domain is specified by two 1D arrays
173+ units, perhaps metres, or latitude/longitude angles , or for a spherical image
174+ as azimuth and colatitude angles . The domain is specified by two 1D arrays
150175 that map the pixel coordinate to the domain variable.
151176
152177 **Binary images**
153178
154- If ``binary`` is True the image is converted to a binary image, where zero valued
179+ If ``binary`` is True, the image is converted to a binary image, where zero valued
155180 pixels are set to False and all other values are set to True. To create an
156181 image where pixels have integer values of 0 and 1 use the ``dtype`` option::
157182
@@ -165,16 +190,18 @@ def __init__(
165190
166191 >>> from machinevisiontoolbox import Image
167192 >>> import numpy as np
168- >>> Image([[1, 2], [3, 4]])
193+ >>> img = Image([[1, 2], [3, 4]])
194+ >>> print(img)
195+ >>> img.print()
169196 >>> Image(np.array([[1, 2], [3, 4]]))
170197 >>> Image([[1, 2], [3, 1000]])
171198 >>> Image([[0.1, 0.2], [0.3, 0.4]])
172199 >>> Image([[True, False], [False, True]])
173200
174- :note: By default the encapsulated pixel data is a reference to
175- the passed image data.
201+ .. warning:: If an image is constructed from an existing :class:`Image` instance or a Numpy array,
202+ the encapsulated Numpy array is, by default, a *reference* to the passed image data.
203+ Use the option ``copy=True`` if you want to copy the data.
176204
177- :seealso: :meth:`colororder` :meth:`colororder_str`
178205 """
179206 self ._A = None
180207 self ._name = None
@@ -1919,7 +1946,7 @@ def lenkey(key, max):
19191946 else :
19201947 raise ValueError ("invalid slice" )
19211948
1922- def pixel (self , u : int , v : int ) -> int | float | int | float :
1949+ def pixel (self , u : int , v : int ) -> int | float :
19231950 """
19241951 Return pixel value
19251952
@@ -1947,10 +1974,10 @@ def pixel(self, u: int, v: int) -> int | float | int | float:
19471974 >>> from machinevisiontoolbox import Image
19481975 >>> img = Image.Read("flowers4.png", mono=True)
19491976 >>> pix = img.pixel(100, 200)
1950- >>> pix
1977+ >>> pix # grey scale pixel value
19511978 >>> img = Image.Read("flowers4.png")
19521979 >>> pix = img.pixel(100, 200)
1953- >>> pix
1980+ >>> pix # color pixel value (R, G, B)
19541981
19551982 :seealso: :meth:`__getitem__` :meth:`roi`
19561983 """
0 commit comments