工作记录

1.np.where 返回满足条件的位置
aa[np.where(array1>doubleThreshold)]=1
2.图像处理中,灰度图显示并不是按实际的灰度值进行显示:
a=np.zeros([512,512]) for i in range(512): for j in range(512): a[i,j]=255

Paste_Image.png

灰度值的范围为0-255:0:黑色 255:白色。
现在本来应该全显示为白色,却都显示为黑色,下面一探究竟。

PIL官方文档PIL

pyplot的显示有自己的配色方案,所以可能显示并不是灰度值,正确的做法如下

a=np.zeros([512,512]) I=Image.fromarray(a).convert('L') I.save('test.png')

Paste_Image.png

3.Mode #
The mode of an image defines the type and depth of a pixel in the image. The current release supports the following standard modes:
1 (1-bit pixels, black and white, stored with one pixel per byte)

L (8-bit pixels, black and white)

P (8-bit pixels, mapped to any other mode using a colour palette)

RGB (3x8-bit pixels, true colour)

RGBA (4x8-bit pixels, true colour with transparency mask)

CMYK (4x8-bit pixels, colour separation)

YCbCr (3x8-bit pixels, colour video format)

I (32-bit signed integer pixels)

F (32-bit floating point pixels)

3.pickle

写入文件
f1 = file('temp.pkl', 'wb') pickle.dump(a1, f1, True)
读pickle文件
import cPickle as pickle f2 = file('dcmdata.pkl', 'rb') dcmdata=pickle.load(f2)

numpy.nonzero 返回坐标
x = np.array([[1,0,0], [0,2,0], [1,1,0]]) x
array([[1, 0, 0], [0, 2, 0], [1, 1, 0]])
np.nonzero(x)
`
(array([0, 1, 2, 2], dtype=int64), array([0, 1, 0, 1], dtype=int64))

`

numpy.count_nonzero 返回个数

    np.count_nonzero(np.eye(4))

4
np.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]])
5
np.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]], axis=0)
array([1, 1, 1, 1, 1])
np.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]], axis=1)
array([2, 3])

可用来判断符合某一条件的个数:

np.count_nonzero(examplearray==5)

5.安装keras,使用

`
pip install keras

`

6.pickle在python2与python3之间的兼容性问题:

直接load会出现

``
UnicodeDecodeError: 'ascii' codec can't decode byte 0xca in position 0: ordinal not in range(128)

``
的问题。

解决方法:

airway=pickle.load(f2,encoding='latin1')

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容