novice
Module: novice
skimage.novice
A special Python image submodule for beginners.
Description
skimage.novice
provides a simple image manipulation interface for beginners. It allows for easy loading, manipulating, and saving of image files.
This module is primarily intended for teaching and differs significantly from the normal, array-oriented image functions used by scikit-image.
Note
This module uses the Cartesian coordinate system, where the origin is at the lower-left corner instead of the upper-right and the order is x, y instead of row, column.
Examples
We can create a Picture object open opening an image file:
>>> from skimage import novice >>> from skimage import data >>> picture = novice.open(data.data_dir + '/chelsea.png')
We can display pictures (after running this command, close the window to access the prompt again):
>>> picture.show()
Pictures know their format:
>>> picture.format 'png'
... and where they came from:
>>> picture.path.endswith('chelsea.png') True
... and their size:
>>> picture.size (451, 300) >>> picture.width 451
As a reminder, we can preview the picture with our earlier command:
>>> picture.show()
Changing size
resizes the picture.
>>> picture.size = (45, 30)
We can preview the changes we made to the picture with the compare
command:
>>> picture.compare()
You can iterate over pixels, which have RGB values between 0 and 255, and know their location in the picture.
>>> for pixel in picture: ... if (pixel.red > 128) and (pixel.x < picture.width): ... pixel.red = pixel.red / 2
Pictures know if they’ve been modified from the original file
>>> picture.modified True >>> print(picture.path) None
Pictures can be indexed like arrays
>>> picture[0:20, 0:20] = (0, 0, 0)
Saving the picture updates the path attribute, format, and modified state.
>>> picture.save('save-demo.jpg') >>> picture.path.endswith('save-demo.jpg') True >>> picture.format 'jpeg' >>> picture.modified False
An image can also be restored to its original state after modification:
>>> picture[0:20, 0:20] = (0, 0, 0) >>> picture.compare() >>> picture.reset() >>> picture.compare()
skimage.novice.open (path) | Return Picture object from the given image path. |
skimage.novice.Picture ([path, array, xy_array]) | A 2-D picture made up of pixels. |
open
-
skimage.novice.open(path)
[source] -
Return Picture object from the given image path.
Picture
-
class skimage.novice.Picture(path=None, array=None, xy_array=None)
[source] -
Bases:
object
A 2-D picture made up of pixels.
Examples
Load an image from a file:
>>> from skimage import novice >>> from skimage import data >>> picture = novice.open(data.data_dir + '/chelsea.png')
Load an image from a URL (the URL must start with
http(s)://
orftp(s)://
):>>> picture = novice.open('http://scikit-image.org/_static/img/logo.png')
Create a blank 100 pixel wide, 200 pixel tall white image:
>>> pic = Picture.from_size((100, 200), color=(255, 255, 255))
Use numpy to make an RGB byte array (shape is height x width x 3):
>>> import numpy as np >>> data = np.zeros(shape=(200, 100, 3), dtype=np.uint8) >>> data[:, :, 0] = 255 # Set red component to maximum >>> pic = Picture(array=data)
Get the bottom-left pixel:
>>> pic[0, 0] Pixel(red=255, green=0, blue=0, alpha=255)
Get the top row of the picture:
>>> pic[:, pic.height-1] Picture(100 x 1)
Set the bottom-left pixel to black:
>>> pic[0, 0] = (0, 0, 0)
Set the top row to red:
>>> pic[:, pic.height-1] = (255, 0, 0)
Attributes
path
The path to the picture. array
Image data stored as numpy array. xy_array
Image data stored as numpy array with origin at the bottom-left. -
__init__(path=None, array=None, xy_array=None)
[source]
-
alpha
-
The transparency component of the pixel (0-255).
-
array
-
Image data stored as numpy array.
-
blue
-
The blue component of the pixel (0-255).
-
compare()
[source] -
Compare the image to its unmodified version.
-
format
-
The image format of the picture.
-
static from_size(size, color='black')
[source] -
Return a Picture of the specified size and a uniform color.
Parameters: size : tuple
Width and height of the picture in pixels.
color : tuple or str
RGB or RGBA tuple with the fill color for the picture [0-255] or a valid key in
color_dict
.
-
green
-
The green component of the pixel (0-255).
-
height
-
The height of the picture.
-
modified
-
True if the picture has changed.
-
path
-
The path to the picture.
-
red
-
The red component of the pixel (0-255).
-
reset()
[source] -
Reset image to its original state, removing modifications.
-
rgb
-
The RGB color components of the pixel (3 values 0-255).
-
rgba
-
The RGBA color components of the pixel (4 values 0-255).
-
save(path)
[source] -
Saves the picture to the given path.
Parameters: path : str
Path (with file extension) where the picture is saved.
-
show()
[source] -
Display the image.
-
size
-
The size (width, height) of the picture.
-
width
-
The width of the picture.
-
xy_array
-
Image data stored as numpy array with origin at the bottom-left.
-
© 2011 the scikit-image team
Licensed under the BSD 3-clause License.
http://scikit-image.org/docs/0.12.x/api/skimage.novice.html