Pengonversi kode gambar ke python

Seni ASCII adalah teknik desain grafis yang menggunakan komputer untuk presentasi dan terdiri dari gambar-gambar yang disatukan dari 95 karakter yang dapat dicetak (dari total 128) yang ditentukan oleh Standar ASCII dari tahun 1963 dan kumpulan karakter yang sesuai dengan ASCII dengan karakter tambahan yang dipatenkan (di luar 128 . Istilah ini juga secara longgar digunakan untuk menyebut seni visual berbasis teks pada umumnya. Seni ASCII dapat dibuat dengan editor teks apa pun dan sering digunakan dengan bahasa bentuk bebas. Sebagian besar contoh seni ASCII membutuhkan font dengan lebar tetap (font tidak proporsional, seperti pada mesin tik tradisional) seperti Courier untuk presentasi. Di antara contoh seni ASCII tertua yang diketahui adalah kreasi pelopor seni komputer Kenneth Knowlton dari sekitar tahun 1966, yang bekerja untuk Bell Labs pada saat itu. “Studi dalam Persepsi I” oleh Ken Knowlton dan Leon Harmon dari tahun 1966 menunjukkan beberapa contoh seni ASCII awal mereka. Seni ASCII diciptakan, sebagian besar, karena printer awal sering kekurangan kemampuan grafis dan dengan demikian karakter digunakan sebagai pengganti tanda grafis. Selain itu, untuk menandai pembagian antara pekerjaan cetak yang berbeda dari pengguna yang berbeda, printer massal sering menggunakan seni ASCII untuk mencetak spanduk besar, membuat pembagian lebih mudah dikenali sehingga hasilnya dapat lebih mudah dipisahkan oleh operator komputer atau juru tulis. Seni ASCII juga digunakan dalam email awal ketika gambar tidak dapat disematkan. Anda dapat mengetahui lebih banyak tentang mereka. [Sumber. wiki

Bagaimana itu bekerja.  

berikut adalah langkah-langkah yang diperlukan program untuk menghasilkan ASCII
gambar.  

  • Ubah gambar input menjadi skala abu-abu
  • Pisahkan gambar menjadi ubin M×N
  • Perbaiki M (jumlah baris) agar sesuai dengan rasio aspek gambar dan font
  • Hitung kecerahan rata-rata untuk setiap petak gambar, lalu cari karakter ASCII yang sesuai untuk masing-masing petak
  • Kumpulkan deretan string karakter ASCII dan cetak ke file untuk membentuk gambar akhir

Persyaratan

Anda akan melakukan program ini dengan python dan kami akan menggunakan Bantal yang merupakan Pustaka Pencitraan Python untuk membaca gambar, mengakses data dasarnya, membuat dan memodifikasinya, dan juga modul ilmiah Numpy untuk menghitung rata-rata

Kode
Anda akan mulai dengan menentukan level skala abu-abu yang digunakan untuk membuat seni ASCII. Kemudian Anda akan melihat bagaimana gambar dibagi menjadi ubin dan bagaimana kecerahan rata-rata dihitung untuk ubin tersebut. Selanjutnya, Anda akan berupaya mengganti petak dengan karakter ASCII untuk menghasilkan hasil akhir. Terakhir, Anda akan menyiapkan parsing baris perintah untuk program agar pengguna dapat menentukan ukuran output, nama file output, dan seterusnya
 

Mendefinisikan Level Grayscale dan Grid

Sebagai langkah pertama dalam membuat program Anda, tentukan dua level skala abu-abu yang digunakan untuk mengubah nilai kecerahan menjadi karakter ASCII sebagai nilai global.  

>>>gscale1 = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~i!lI;:,\"^`". "    #70 levels of gray
>>>gscale2 = "@%#*+=-:. "         #10 levels of gray

Nilai gscale1 pada u adalah ramp skala abu-abu 70 tingkat, dan gscale2 pada v adalah ramp skala abu-abu 10 tingkat yang lebih sederhana. Kedua nilai ini disimpan sebagai string, dengan rentang karakter yang berkembang dari paling gelap ke paling terang
Sekarang setelah Anda memiliki landai skala abu-abu, Anda dapat mengatur gambarnya. Kode berikut membuka gambar dan membaginya menjadi kisi
 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
_

Menghitung kecerahan rata-rata
Selanjutnya, Anda menghitung kecerahan rata-rata untuk petak dalam gambar skala abu-abu. Fungsi getAverageL() melakukan tugasnya
 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))

Pertama, petak gambar diteruskan sebagai objek Gambar PIL. Ubah gambar menjadi larik numpy pada langkah kedua, di mana titik 'im' menjadi larik kecerahan dua dimensi untuk setiap piksel. Pada langkah ketiga, Anda menyimpan dimensi (lebar dan tinggi) gambar. Pada langkah keempat, numpy. average() menghitung rata-rata nilai kecerahan pada gambar dengan menggunakan numpy. reshape() untuk terlebih dahulu mengonversi larik dua dimensi dari lebar dan tinggi dimensi (w,h) menjadi ?at larik satu dimensi yang panjangnya merupakan hasil kali lebar dengan tinggi (w*h). Yang numpy. rata-rata() kemudian menjumlahkan nilai-nilai array ini dan menghitung rata-ratanya
 

Menghasilkan Konten ASCII dari Gambar

    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval

Di bagian program ini, citra ASCII pertama kali disimpan sebagai daftar string, yang diinisialisasi pada langkah pertama. Selanjutnya, Anda mengulangi jumlah petak gambar baris yang dihitung, dan pada langkah kedua dan baris berikutnya, Anda menghitung koordinat y awal dan akhir dari setiap petak gambar. Meskipun ini adalah perhitungan floating-point, pangkas menjadi bilangan bulat sebelum meneruskannya ke metode pemangkasan gambar. Selanjutnya, karena membagi gambar menjadi petak akan menghasilkan petak tepi dengan ukuran yang sama hanya jika lebar gambar adalah kelipatan bilangan bulat dari jumlah kolom, koreksi koordinat y petak di baris terakhir dengan menyetel koordinat y ke . Dengan melakukannya, Anda memastikan tepi atas gambar tidak terpotong. Pada langkah ketiga, Anda menambahkan string kosong ke dalam ASCII sebagai cara ringkas untuk merepresentasikan baris gambar saat ini. Anda akan mengisi string ini selanjutnya. (Anda memperlakukan string sebagai daftar karakter. ) Pada langkah keempat dan baris berikutnya, Anda menghitung koordinat x kiri dan kanan dari setiap petak, dan langkah kelima, Anda mengoreksi koordinat x untuk petak terakhir dengan alasan yang sama saat Anda mengoreksi koordinat y. Gunakan gambar. crop() pada langkah keenam untuk mengekstrak petak gambar dan meneruskan petak tersebut ke fungsi getAverageL() yang ditentukan di atas, Anda menurunkan skala nilai kecerahan rata-rata dari [0, 255] ke [0, 9] (rentang nilai . Anda kemudian menggunakan gscale2 (string ramp yang disimpan) sebagai tabel pencarian untuk ASCII Art 95 nilai ASCII yang relevan. Baris pada langkah delapan serupa, kecuali bahwa ini hanya digunakan ketika baris perintah ?ag diatur untuk menggunakan ramp dengan 70 level. Terakhir, Anda menambahkan nilai ASCII yang dicari, gsval, ke baris teks pada langkah terakhir, dan kode diulang hingga semua baris diproses
Menambahkan antarmuka Baris Perintah dan Menulis ASCII Art-Strings ke file teks
Untuk menambahkan antarmuka baris perintah, gunakan argparse modul built-in python.  
Dan sekarang akhirnya, ambil daftar string karakter ASCII yang dihasilkan dan tulis string tersebut ke file teks
 

# open a new text file
>>> f = open(outFile, 'w')
# write each string in the list to the new file
>>> for row in aimg:
..    f.write(row + '\n')
# clean up
>>> f.close()
_

Kemudian tambahkan bagian-bagian ini untuk membuat program Anda. Kode lengkap diberikan di bawah ini
 

Direkomendasikan. Harap coba pendekatan Anda pada {IDE} terlebih dahulu, sebelum melanjutkan ke solusi

Piton




# Python code to convert an image to ASCII image.

import sys, random, argparse

import

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
0

import

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
2

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
3
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
4import
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
6

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
_7

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
_8

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
_9

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
0
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
2

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
_3

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
4
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
6

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
7
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
8

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
0

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
2

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
0

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
6

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
8
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
# open a new text file
>>> f = open(outFile, 'w')
# write each string in the list to the new file
>>> for row in aimg:
..    f.write(row + '\n')
# clean up
>>> f.close()
0

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
# open a new text file
>>> f = open(outFile, 'w')
# write each string in the list to the new file
>>> for row in aimg:
..    f.write(row + '\n')
# clean up
>>> f.close()
2

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
# open a new text file
>>> f = open(outFile, 'w')
# write each string in the list to the new file
>>> for row in aimg:
..    f.write(row + '\n')
# clean up
>>> f.close()
4
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
# open a new text file
>>> f = open(outFile, 'w')
# write each string in the list to the new file
>>> for row in aimg:
..    f.write(row + '\n')
# clean up
>>> f.close()
6

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
# open a new text file
>>> f = open(outFile, 'w')
# write each string in the list to the new file
>>> for row in aimg:
..    f.write(row + '\n')
# clean up
>>> f.close()
8

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
0
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
1
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
2
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
3

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
7
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
5

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
0

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
9

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
0

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9# Python code to convert an image to ASCII image.3

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9# Python code to convert an image to ASCII image.5 # Python code to convert an image to ASCII image.6

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9# Python code to convert an image to ASCII image.8

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9import0
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1 import2import3import4import5import6

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9import8

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9sys, random, argparse0
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1 sys, random, argparse2sys, random, argparse3sys, random, argparse4sys, random, argparse5sys, random, argparse6

________2______9sys, random, argparse8sys, random, argparse9import0 import1 import2

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9import4

________2______9import6

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1 import8________264______9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
00

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
02

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
04
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1 import6import9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
08

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
10

________2______9

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
12
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
14
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
15import9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
17

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
_9

________2______9sys, random, argparse8sys, random, argparse9

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
22 ________264______1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
24

________2______9sys, random, argparse8sys, random, argparse9

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
28 import1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
30

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
32

________2______9

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
34
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
35
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
36
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
37

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
38sys, random, argparse8sys, random, argparse9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
41import6

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
38
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
44sys, random, argparse3import6

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
48

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
50
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
52

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
54

________2______9

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
56
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
57
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
58
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
59
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
60

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
38
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
62
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
14
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
65
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
2
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
17

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
38
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
69
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
14
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
72
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
73sys, random, argparse5import6
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
2________1______17

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
_38
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
79

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
38
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
34
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
57
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
12
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
86sys, random, argparse5
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
88

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
69
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
92

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
_38
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
94

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
_38
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
96

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
38
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
56
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
99
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
58
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
59
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
02

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
04

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
06
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
14
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
09
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
2
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
11

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
13
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
14
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
16
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
73sys, random, argparse5import6
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
2________2______11

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
79

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
34
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
99
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
00
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
86sys, random, argparse5
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
88

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
33
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
13
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1 import8

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
38

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
40
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
42

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
44

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
46
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
14
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
49

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
_89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
51

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
34
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
54

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
33
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
56
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
58
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
14
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
60________43______2
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
62import6________264______9________2______2_5______6______6

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
_89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
68
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
88

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
33
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
56
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
73
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
14
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
60________43______2
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
77import6________264______9________2______2_5______6______6

 

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
83

    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
89
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
85
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
73
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
56

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
_9

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
91

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
$python "ASCII_IMAGE_GENERATOR.py" --file data/11.jpg --cols 120
0
    # open image and convert to grayscale
>>>    image = Image.open(fileName).convert('L')
    # store dimensions
>>>    W, H = image.size[0], image.size[1]
    # compute width of tile
>>>    w = W/cols
    # compute tile height based on aspect ratio and scale
>>>    h = w/scale
    # compute number of rows
>>>    rows = int(H/h)
50

 

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
_95

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
7
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
97

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
99

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
01
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
03

________2______9

    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
05
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
07
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
09

#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
9
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
11

________2______9

    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
13
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
54
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
55
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
57
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
58
#Given PIL Image, return average value of grayscale value
>>>def getAverageL(image):
    # get image as numpy array
..    im = np.array(image)
    # get shape
..    w,h = im.shape
    # get average
..    return np.average(im.reshape(w*h))
1
    # ascii image is a list of character strings
>>>    aimg = []
    # generate list of dimensions
>>>    for j in range(rows):
..        y1 = int(j*h)
..        y2 = int((j+1)*h)
        # correct last tile
..        if j == rows-1:
..            y2 = H
        # append an empty string
..        aimg.append("")
..        for i in range(cols):
            # crop image to tile
..            x1 = int(i*w)
..            x2 = int((i+1)*w)
            # correct last tile
..            if i == cols-1:
..                x2 = W
            # crop image to extract tile
..            img = image.crop((x1, y1, x2, y2))
            # get average luminance
..            avg = int(getAverageL(img))
            # look up ascii char
..            if moreLevels:
..                gsval = gscale1[int((avg*69)/255)]
..            else:
..                gsval = gscale2[int((avg*9)/255)]
            # append ascii char to string
..            aimg[j] += gsval
60import6

Bagaimana cara mengubah gambar menjadi kode dengan Python?

Tambahkan referensi perpustakaan (impor perpustakaan) ke proyek Python Anda. Buka file gambar sumber dengan Python. Panggil metode 'save()', meneruskan nama file keluaran dengan ekstensi HTML. Dapatkan hasil konversi gambar sebagai HTML

Bagaimana cara mengubah gambar menjadi kode?

Langkah 1 .
Simpan gambar secara lokal atau online. .
Buka dokumen HTML. .
Sesuaikan lebar gambar sesuai keinginan Anda, dalam satuan piksel. .
Sesuaikan tinggi gambar sesuai keinginan Anda, dalam hal piksel
Gabungkan penyesuaian lebar dan tinggi seperlunya
Ubah gambar menjadi tautan jika diinginkan

Bagaimana cara mengubah PNG menjadi teks Python?

Cara mengonversi PNG ke TXT .
Instal 'Anggap. Kata-kata untuk Python via. BERSIH'
Tambahkan referensi perpustakaan (impor perpustakaan) ke proyek Python Anda
Buka file PNG sumber dengan Python
Panggil metode 'save()', meneruskan nama file keluaran dengan ekstensi TXT
Dapatkan hasil konversi PNG sebagai TXT