当前位置:网站首页>The imshow function of Matplotlib displays grayscale images. Vmin and vmax2 parameters should be set
The imshow function of Matplotlib displays grayscale images. Vmin and vmax2 parameters should be set
2022-06-29 13:22:00 【Fenghua Mingyuan】
matplotlib Of imshow Functions are very complex , Support a lot of people colormap, Change and so on . When using this function, you need to pay attention to the parameter settings , Especially the gray image .
imshow Yes 2 Parameters vmin and vmax. When displaying grayscale images , To set the upper vmin=0 as well as vmax=255. otherwise imshow Function will automatically adjust the value .
The values entered are :X1 = [[1,2,3],[4,5,6]] and X2 = [[111,112,113],[114,115,116]]. If not set vmin and vmax Then the image is similar .
#coding:utf8
import matplotlib.pyplot as plt
X1 = [[1,2,3],[4,5,6]]
X2 = [[111,112,113],[114,115,116]]
fig = plt.figure()
ax = fig.add_subplot(121)
im = ax.imshow(X1,cmap=plt.cm.gray)
plt.colorbar(im, cax=None, ax=None,shrink=0.5)
ax = fig.add_subplot(122)
im = ax.imshow(X2, cmap=plt.cm.gray)
plt.colorbar(im, cax=None, ax=None,shrink=0.5)
plt.show()
If you set vmin=0,vmax=255, The situation will be different :
The first 3 Zhang heti 4 The gray value setting of the image is [0,255], here X1 and X2 Because the value is close , Display as a near solid color rather than a color block with a large difference in grayscale . So in use matplotlib Of imshow Pay attention to this situation when using the function , Otherwise, you may not get the desired results , For example, there may be no significant change in the grayscale .
# coding:utf8
import matplotlib.pyplot as plt
X1 = [[1, 2, 3], [4, 5, 6]]
X2 = [[111, 112, 113], [114, 115, 116]]
fig = plt.figure()
ax = fig.add_subplot(221)
im = ax.imshow(X1, cmap=plt.cm.gray)
plt.colorbar(im, cax=None, ax=None, shrink=0.5)
ax = fig.add_subplot(222)
im = ax.imshow(X2, cmap=plt.cm.gray)
plt.colorbar(im, cax=None, ax=None, shrink=0.5)
ax = fig.add_subplot(223)
im = ax.imshow(X1, cmap=plt.cm.gray, vmin=0, vmax=255)
plt.colorbar(im, cax=None, ax=None, shrink=0.5)
ax = fig.add_subplot(224)
im = ax.imshow(X2, cmap=plt.cm.gray, vmin=0, vmax=255)
plt.colorbar(im, cax=None, ax=None, shrink=0.5)
plt.show()
边栏推荐
- Detailed explanation on configuration and commissioning of third-party servo of Beifu TwinCAT -- Taking Huichuan is620n as an example
- Hystrix circuit breaker
- AOSP ~ logcat persistence
- 力扣:合并两个有序链表
- C#实现二叉树的先序遍历、中序遍历、后序遍历
- C # implements the operations of sequence table definition, insertion, deletion and search
- Windwos10 installing sshd service
- CVPR2022 | 通过目标感知Transformer进行知识蒸馏
- Matlab to find the limit
- The role of each part of Neural Network & thoroughly understand neural network
猜你喜欢

神经网络各个部分的作用 & 彻底理解神经网络

Mirror vulnerability scanner: trivy

Interview shock 61: tell me about MySQL transaction isolation level?

倍福控制器连接松下EtherCAT伺服注意事项

OPC of Beifu twincat3_ UA communication test case

QT signal and slot

qt 自定义控件 :取值范围

三维模型下载与动画控制

Proteus simulation of buck switching power supply based on 51 single chip microcomputer

Force buckle: merging two ordered linked lists
随机推荐
bind原理及模拟实现
3D model downloading and animation control
Server monitoring netdata panel configuring mail service
C language simulation to realize all character functions
编写一个shell脚本,求一个数的”逆序数“
C#实现二叉树的层次遍历
Hystrix circuit breaker
C#实现堆栈结构的定义、入栈、出栈
netdata邮件告警配置
C binary tree structure definition and node value addition
qt json
服务器上的RTC时间与世界时间不一致解决办法
倍福PLC通过CANOpen通信控制伺服
mysql调优
QT custom control: value range
Acwing 234 abandoning testing
Golang image/png processing image rotation writing
C # output the middle order traversal through the clue binary tree
Aes-128-cbc-pkcs7padding encrypted PHP instance
Ordinary users use vscode to log in to SSH and edit the root file