私はこの学校のプロジェクトを与えられました。このプロジェクトの目標は、写真を撮り、RLE メソッドを適用してバイナリ ファイル (.txt) に圧縮し、スペースを節約することです。そして、3日間苦労した後、私は問題を抱えています。
def lecture_fichier_compresse():
f2=open("data2.txt",'rb') #open a binary file in reading mod.
im3=zeros((962,800,3),dtype="uint8") #create picture which size is 962*800 where every pixels are coded on 3 bytes.
d=0#pixel counter
i=0#lign indexation
j=0#column indexation
b=ord(f2.read(1))# the informations are read a first time
a=ord(f2.read(1))
rouge=ord(f2.read(1))
vert=ord(f2.read(1))
bleu=ord(f2.read(1))
while i!=im3.shape[0]: #as long as it doesn't reach the final lign
if d<=(a+b*255):
im3[i,j,0] = rouge
im3[i,j,1] = vert
im3[i,j,2] = bleu
d+=1
j+=1
if j==im3.shape[1]:
j=0
i+=1
else: #resets pixel counter and starts reading next informations
d=0
b=ord(f2.read(1))
a=ord(f2.read(1))
rouge=ord(f2.read(1))
vert=ord(f2.read(1))
bleu=ord(f2.read(1))
f2.close()
imsave("Copie_compresse.bmp",im3)
return im3
imshow(lecture_fichier_compresse());show()
pgrmを実行すると、タイトルに書かれているこのエラーが表示されます。それ自体を16進数で書いているので、これは私が修正するのが不可能だと思うものです.
詳細情報は次のとおりです。ここでは、.bmp などの形式で通常行うように、ピクセルはバイトを使用してコーディングされません。ここで、RLE は同じ線上にある同一のピクセルを検索し、3 レベルの色を比較して、そのピクセルに遭遇した回数をカウントします。最後に、RGB バイトよりも 2 つの追加バイト (a と b) に格納されます。a はピクセル数です。b は、ピクセルの 255 スタックの数です。(私はデータを 8 ビットにコーディングしており、その画像は通常 255*255 サイズよりも大きいため)