1

I,m trying encode, send and put some noise,and decode an Image in Python app using Reed-Solomon coder

I have converted imagage from PIL to numpy array. Now I'm trying to encode this array and then decode it. But I have problem with code word. It's too long. Does anyone know how to solve this problem. Thank You in advance

Error message: ValueError: Message length is max 223. Message was 226

import unireedsolomon as rs
from PIL import Image
import numpy as np

class REED
  def __init__(self):

    self.img = None
    self.numpyImg = None


  def loadPictureAndConvertToNumpyArray(self):
    self.img = Image.open('PATH')
    self.img.load()
    self.numpyImg = np.array(self.img)

  def reedSolomonEncode(self):

    coder = rs.RSCoder(255,223)
    self.numpyImg = coder.encode(self.numpyImg)
pythonBeginer
  • 41
  • 1
  • 8

1 Answers1

0

The ReedSolomon package's github page clearly indicates that you cannot encode arrays that are larger than k (223 in your case). This means that you have to split your image first before encoding it. You can split it into chunks of 223 and then work on the encoded chunks:

k = 223
imgChunks = np.array_split(self.numpyImg, range(k, self.numpyImg.shape[0], k))
encodedChunks = [coder.encode(chunk) for chunk in imgChunks]
ma3oun
  • 3,681
  • 1
  • 21
  • 33
  • That what I' ve been looking for. Than You a lot. – pythonBeginer May 03 '19 at 18:54
  • @pythonBeginer - you could treat the image as a matrix. The rs library could be used to correct the rows, an the matrix could be transposed, so what were the columns are now rows, allowing the rs library to correct the columns, then transpose back. If the rs library handles erasures it could benefit from having failed rows marked as erasures when correcting columns. – rcgldr May 03 '19 at 21:05