示例#1
0
 def getSpatial(self,channel="Y"):
   """
     This method returns one decompressed colour channel as a matrix.
     The appropriate JPEG coefficient matrix is dequantised 
     (using the quantisation tables held by the object) and
     inverse DCT transformed.
   """
   X = self.getCoefMatrix(channel)
   Q = self.getQMatrix(channel)
   (M,N) = shape(X)
   assert M % 8 == 0, "Image size not divisible by 8"
   assert N % 8 == 0, "Image size not divisible by 8"
   D = X * base.repmat( Q, (M/8, N/8) )
   S = ibdct(D)
   #assert max( abs(S).flatten() ) <=128, "Image colours out of range"
   return (S + 128 ).astype(np.float32)
示例#2
0
 def getCalibrated(self,channel="Y",mode="all"):
   """
     Return a calibrated coefficient matrix for the given channel.
     Channel may be "Y", "Cb", or "Cr" for YCbCr format.
     For Grayscale images, it may be None or "Y".
   """
   S = self.getSpatial(channel)
   (M,N) = shape(S)
   assert M % 8 == 0, "Image size not divisible by 8"
   assert N % 8 == 0, "Image size not divisible by 8"
   if mode == "col":
      S1 = S[:,4:(N-4)]
      cShape = ( M/8, N/8-1 )
   else:
     S1 = S[4:(M-4),4:(N-4)]
     cShape = ( (M-1)/8, (N-1)/8 )
   D = bdct(S1 - 128)
   X = D / base.repmat( self.getQMatrix(channel), cShape )
   return np.round(X)
示例#3
0
  def getCalSpatial(self,channel="Y"):
    """
      Return the decompressed, calibrated, grayscale image.
      A different colour channel can be selected with the channel
      argument.
    """

# We calibrate the image, obtaining a JPEG matrix.
#    ::

    C = self.getCalibrated(channel)

# The rest is straight forward JPEG decompression.
#    ::

    (M,N) = shape(C)
    cShape = (M/8,N/8)
    D = C * base.repmat( self.getQMatrix(channel), cShape )
    S = np.round( ibdct(D) + 128 )
    return S.astype(np.uint8)
示例#4
0
def dequantise(C, Q):
    """Dequantise JPEG coefficients using the quantisation matrix Q."""
    [k, l] = C.shape
    [m, n] = Q.shape
    rep = (k / m, l / n)
    return C * repmat(Q, rep)
示例#5
0
def quantise(C, Q):
    """Quantise DCT coefficients using the quantisation matrix Q."""
    [k, l] = C.shape
    [m, n] = Q.shape
    rep = (k / m, l / n)
    return C / repmat(Q, rep)