工作記錄

1.np.where 返回滿足條件的位置
aa[np.where(array1>doubleThreshold)]=1
2.圖像處理中,灰度圖顯示并不是按實(shí)際的灰度值進(jìn)行顯示:
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:白色。
現(xiàn)在本來應(yīng)該全顯示為白色,卻都顯示為黑色,下面一探究竟。

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 返回坐標(biāo)
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 返回個數(shù)

    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])

可用來判斷符合某一條件的個數(shù):

np.count_nonzero(examplearray==5)

5.安裝keras,使用

`
pip install keras

`

6.pickle在python2與python3之間的兼容性問題:

直接load會出現(xiàn)

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

``
的問題。

解決方法:

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容