欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python图像学基础

程序员文章站 2022-03-20 23:30:51
...

一、列表
list(),int()都属于强制类型转化,将字符串转化为list列表
一维数组 a=[1 2 3 4 5 6]
a[4]=5
二维数组 b=[[1 2][3 4][5 6][7 8]]
b[1][1]=4
三维数组 c=[[[1 2][3 4]][[5 6][7 8]]]
c[1][1][1]=8
二、图像转字符画
目的:将图像转化按照列表格式输出

show_height=40#纵向打印字符数
show_width=40#横向打印字符数
ascii_char=list("[email protected]%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. ")
print(ascii_char[10])
#读取图片
pic=cv2.imread("E:/Literature/material/121398.jpg")
print(type(pic))
#<class 'numpy.ndarray'>
#图像灰度化
gray=pic[:,:,0]*0.2+pic[:,:,1]*0.7+pic[:,:,2]*0.1
print(gray)
print(len(gray))#长
print(len(gray[0]))#宽
pic_height,pic_width,pic_c=pic.shape
print(pic_height)
print(pic_width)
for i in range(show_height):
    y=int(i*pic_height/show_height)#获取真实图片上某个像素点的纵坐标
    text = ""
    for j in range(show_width):
        x = int(j * pic_width / show_width)  # 获取真实图片上某个像素点的横坐标
        text+=ascii_char[int(gray[y][x]/256*len(ascii_char))]
    print(text)
#结果
vvccvvvuvvvvvqcvvvvvcvvvvccccccvvvvvvvvv#每行四十的字符
uvvvuuuuuuvvuUXuvcvvvvvvcvccvcvvvvvvvvvv
uuuuuuuvuuuuv1fvvvvvvvvvvvcvvvvvvvvvvvuu
uunuuuuuuuuucYjuuuuuuuuuuuuvuuuuuuuuuuuv
nnnnnnnnnuuuucJunnuununuuuuucLuuunuunnun
xnnxnnnnnnqnJYuznxnnnnnunnnnQ_nnnuuunnnn
xxxxxxxxxxYxrcmx/xxxxxnnnnxnvvunnxnxxxxx
rrrrrrrrrr0cZxM{|rxxxxxxxxxxUz|xxrxxnxxx
jrjjrrrjjrkwJfOUUrnrrrrrrrrrLoz0rxrrxrrr
fjfjfjjjjqqUzaf*OoUjrjjjrrj10czLrrrrrrrr
ffffffffj*hU$Yjcr/cjjjjjjjrmnXxUxjjjjjjj
/[email protected]|jffffjrbtcvprjffjjff
///////tWq%0zU#mbkzYfttttf/pz%80btCftfff
\\\\\/\|b8WCXXr0mQXtt//tt\CqqptxZbuftttt
|||\|\|\hMCYUjnjjrct\/\/f\CdWpdrZQ*|/\\\
(((||||\QdkYXxfcnxv\\\\\l)ok$%cYOpkQ/\\|
))((((((mZbcYYmaL\c\||||-[email protected]\|||
11)))))(qQXXYY0uXfX((((urcYbWpznXUuz)(((
{{{11111mzUUUJcccnY11j/{|qbpMWYvOqvz()))
}{{{{{1{OUYOQXuz0uY)?twpXMqoLBXcXUZJ(111
}}}}}}}1OYm0Jz[t/tzJ)cX#[email protected]{{{
[[[[[[[[email protected]*z*p000zmatqJJXC{[}}
]]]][]]ZY|*%pj(txuJ)vh/fC.jtrLqZtx0n/[[[
-?????-ZO$QwzMZjjbobvXrf)xxuxbkn#fJxU}]]
------]8hWLZcr\[email protected]/0[??
_--_---wcOcQntJ(vnmcCc#8JOJYcUfCr08CdX--
___+[f/[email protected]\0CXrj0xJOckc_-
_+_~zLO0uuJYx\znr|wrUX\+qUJOrL0puUzvqr_-
|fCYJo#YxjXUqfXrx\QnC|\|Y}n/j\WujzxYmp~~
8cqB8/mOrOXYXbQc|{n0r1|(t\fn/tJn(uUmjZi~
XWmjY/qcoQYznr){rYr|txttuCXxzQZJf[{1/cq}
XQzUpCZzr?(Ltr))(/u/jxz0un(rftt\mvffbtU+
QadzLnaZ$0vJnWLut|Z|tOdJnxh%8&d)%&|(1jt>
0JCxM%zvWmvLnu|bjfznrjfx|nzf|tx}QjLnXQ/k
(YbjMUQvvmxOnfX[ttXfxjtva}<aY\QtCj/n|Lx)
UXXXkQUXcOnLnjujfjXxnrcj(0j[OQO/Yj)Qf0UJ
z!cYrcXcYLjJut*&*xjx/xC[\hba{bUnXfmUJLCc
v<vCjuCzzCrJxz--mcrn\[email protected]/xczXxf++Zxdr
v(uxxnJz([email protected]/f/XtfxwJQUrQt{$1v\Qj
cxzu}[email protected]@$jfXnuYUdQCZCCuv|u&*c)Of