picture
Submodule extending the vtkImageActor
object functionality.
Picture
- class vedo.picture.Picture(obj=None, channels=(), flip=False)[source]
Bases:
vtkmodules.vtkRenderingCore.vtkImageActor
,vedo.base.Base3DProp
Derived class of
vtkImageActor
. Used to represent 2D pictures. Can be instantiated with a path file name or with a numpy array.Use Picture.shape to access the number of pixels in x and y.
- Parameters
- append(pictures, axis='z', preserveExtents=False)[source]
Append the input images to the current one along the specified axis. Except for the append axis, all inputs must have the same extent. All inputs must have the same number of scalar components. The output has the same origin and spacing as the first input. The origin and spacing of all other inputs are ignored. All inputs must have the same scalar type.
- Parameters
preserveExtents (bool) – if True, the extent of the inputs is used to place the image in the output. The whole extent of the output is the union of the input whole extents. Any portion of the output not covered by the inputs is set to zero. The origin and spacing is taken from the first input.
from vedo import Picture, dataurl pic = Picture(dataurl+'dog.jpg').pad() pic.append([pic,pic,pic], axis='y') pic.append([pic,pic,pic,pic], axis='x') pic.show(axes=1)
- blend(pic, alpha1=0.5, alpha2=0.5)[source]
Take L, LA, RGB, or RGBA images as input and blends them according to the alpha values and/or the opacity setting for each input.
- clone(transform=False)[source]
Return an exact copy of the input Picture. If transform is True, it is given the same scaling and position.
- enhance()[source]
Enhance a b&w picture using the laplacian, enhancing high-freq edges.
Example
import vedo p = vedo.Picture(vedo.dataurl+'images/dog.jpg').bw() vedo.show(p, p.clone().enhance(), N=2, mode='image')
- extent(ext=None)[source]
Get or set the physical extent that the picture spans. Format is ext=[minx, maxx, miny, maxy].
- fft(mode='magnitude', logscale=12, center=True)[source]
Fast Fourier transform of a picture.
- Parameters
logscale (float) – if non-zero, take the logarithm of the intensity and scale it by this factor.
mode (str) – either [magnitude, real, imaginary, complex], compute the point array data accordingly.
center (bool) – shift constant zero-frequency to the center of the image for display. (FFT converts spatial images into frequency space, but puts the zero frequency at the origin)
- frequencyPassFilter(lowcutoff=None, highcutoff=None, order=3)[source]
Low-pass and high-pass filtering become trivial in the frequency domain. A portion of the pixels/voxels are simply masked or attenuated. This function applies a high pass Butterworth filter that attenuates the frequency domain image with the function
The gradual attenuation of the filter is important. A simple high-pass filter would simply mask a set of pixels in the frequency domain, but the abrupt transition would cause a ringing effect in the spatial domain.
- median()[source]
Median filter that preserves thin lines and corners. It operates on a 5x5 pixel neighborhood. It computes two values initially: the median of the + neighbors and the median of the x neighbors. It then computes the median of these two values plus the center pixel. This result of this second median is the output pixel value.
- modified()[source]
Use in conjunction with
tonumpy()
to update any modifications to the picture array
- pad(pixels=10, value=255)[source]
Add the specified number of pixels at the picture borders. Pixels can be a list formatted as [left,right,bottom,top].
- resize(newsize)[source]
Resize the image resolution by specifying the number of pixels in width and height. If left to zero, it will be automatically calculated to keep the original aspect ratio.
- rotate(angle, center=(), scale=1, mirroring=False, bc='w', alpha=1)[source]
Rotate an image by an angle (anticlockwise).
- smooth(sigma=3, radius=None)[source]
Smooth a Picture with Gaussian kernel.
- Parameters
sigma (int, optional) – number of sigmas in pixel units. The default is 3.
radius (TYPE, optional) – how far out the gaussian kernel will go before being clamped to zero. The default is None.
- text(txt, pos=(0, 0, 0), s=1, c=None, alpha=1, bg=None, font='Theemim', dpi=500, justify='bottom-left')[source]
Build an image from a string.
- threshold(value=None, flip=False)[source]
Create a polygonal Mesh from a Picture by filling regions with pixels luminosity above a specified value.
- tiling(nx=4, ny=4, shift=(0, 0))[source]
Generate a tiling from the current picture by mirroring and repeating it.
- tomesh()[source]
Convert an image to polygonal data (quads), with each polygon vertex assigned a RGBA value.
- tonumpy()[source]
Get read-write access to pixels of a Picture object as a numpy array. Note that the shape is (nrofchannels, nx, ny).
When you set values in the output image, you don’t want numpy to reallocate the array but instead set values in the existing array, so use the [:] operator. Example: arr[:] = arr - 15
If the array is modified call:
picture.modified()
when all your modifications are completed.
- warp(sourcePts=(), targetPts=(), transform=None, sigma=1, mirroring=False, bc='w', alpha=1)[source]
Warp an image using thin-plate splines.
- Parameters
sourcePts (list, optional) – source points.
targetPts (list, optional) – target points.
transform (TYPE, optional) – a vtkTransform object can be supplied. The default is None.
sigma (float, optional) – stiffness of the interpolation. The default is 1.
mirroring (TYPE, optional) – fill the margins with a reflection of the original image. The default is False.
bc (TYPE, optional) – fill the margins with a solid color. The default is ‘w’.
alpha (TYPE, optional) – opacity of the filled margins. The default is 1.