Matplotlib image tutorial

 

Plot numpy array as image¶

Therefore, you store the data in a numpy array (by importing or generating). Let's render it. In Matplotlib, this is imshow()performed using functions.

Here, we will get the drawing object. This object provides you with an easy way to manipulate graphics from prompts.

 

 

 

 

 

 

Apply pseudo-color scheme to image map

Pseudo-color is a useful tool to enhance contrast and visualize data more easily. This is especially useful when using projectors for data presentations-their contrast is usually poor.

Pseudo-color is only relevant for single-channel, grayscale, and luminosity images. We currently have an RGB image. Since R, G and B are all similar (see above or in the data), we can choose a data channel:

 

 

 

 

 

 Now, for brightness (2D, no color) images, the default color map (aka lookup table, LUT) will be applied. The default name is viridis. There are many other options.

 

 

 Please note that you can also use set_cmap()methods to change the color map on an existing print object:

 

 

 

Color reference

It is helpful to understand what value color represents. We can do this by adding a color bar to your graphic:

 

 

 

Check specific data range

Sometimes you want to enhance the contrast of an image, or expand the contrast of a specific area, while sacrificing the difference in color, which does not change much or does not matter.

Histogram is a good tool to find interesting areas. To create a histogram of image data, use a hist()function.

 

 

 Let's adjust the upper limit to effectively "zoom in" a part of the histogram. To this end, we passed the clim parameter to imshow. You can also do this by calling set_clim()the method of the image drawing object

 

 

 

 

 

 You can also use the returned object to specify the climb

 

 

 

Array interpolation scheme¶

We will use the pillow library for loading images to adjust the size of the images.

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/leon-joker/p/12713390.html
Recommended