HAAR変換

 投稿者:しばっち  投稿日:2010年10月30日(土)20時12分59秒
  !'HAAR変換(テストルーチン)

OPTION BASE 0
PUBLIC NUMERIC N
LET  N = 8
DIM A(N, N)
RANDOMIZE
PRINT "初期値"
FOR I = 0 TO N - 1
   FOR J = 0 TO N - 1
      LET  A(J, I) = INT(RND * 255)
      PRINT USING "####":A(J, I);
   NEXT J
   PRINT
NEXT I
PRINT
CALL HAAR2D(N, A, 1)
PRINT "ハール2D変換"
FOR I = 0 TO N - 1
   FOR J = 0 TO N - 1
      PRINT A(J, I);
   NEXT J
   PRINT
NEXT I
CALL HAAR2D(N, A, -1)
PRINT
PRINT "ハール2D逆変換"
FOR I = 0 TO N - 1
   FOR J = 0 TO N - 1
      PRINT USING"####":INT(A(J, I)+.5);
   NEXT J
   PRINT
NEXT I
END

EXTERNAL  SUB HAAR (X(), N, L(), MD)
   OPTION BASE 0
   DIM MAT(N, N)
   !'4*4
4 DATA 1,1,1,1
  DATA 1,1,-1,-1
  DATA 1.414214,-1.414214,0,0
  DATA 0,0,1.414214,-1.414214
  !'8*8
8 DATA 1,1,1,1,1,1,1,1
  DATA 1,1,1,1,-1,-1,-1,-1
  DATA 1.414214,1.414214,-1.414214,-1.414214,0,0,0,0
  DATA 0,0,0,0,1.414214,1.414214,-1.414214,-1.414214
  DATA 2,-2,0,0,0,0,0,0
  DATA 0,0,2,-2,0,0,0,0
  DATA 0,0,0,0,2,-2,0,0
  DATA 0,0,0,0,0,0,2,-2
  SELECT CASE N
  CASE 4
     RESTORE 4
     FOR J = 0 TO N - 1
        FOR I = 0 TO N - 1
           READ MAT(I, J)
           LET MAT(I, J) = MAT(I, J) / 2
        NEXT I
     NEXT J
  CASE 8
     RESTORE 8
     FOR J = 0 TO N - 1
        FOR I = 0 TO N - 1
           READ MAT(I, J)
           LET MAT(I, J) = MAT(I, J) / SQR(8)
        NEXT I
     NEXT J
  END SELECT
  IF MD = 1 THEN
     FOR I = 0 TO N - 1
        LET  S = 0
        FOR K = 0 TO N - 1
           LET  S = S + X(K) * MAT(K, I)
        NEXT K
        LET  L(I) = S
     NEXT I
  ELSE
     FOR I = 0 TO N - 1
        LET  S = 0
        FOR K = 0 TO N - 1
           LET  S = S + X(K) * MAT(I, K)
        NEXT K
        LET  L(I) = S
     NEXT I
  END IF
END SUB

EXTERNAL  SUB HAAR2D(N, S(,), MD)
  OPTION BASE 0
  DIM X(N), Y(N)
  FOR J = 0 TO N - 1
     FOR I = 0 TO N - 1
        LET X(I) = S(I, J)
     NEXT I
     CALL HAAR (X, N, Y, MD)
     FOR I = 0 TO N - 1
        LET  S(I, J) = Y(I)
     NEXT I
  NEXT J
  FOR J = 0 TO N - 1
     FOR I = 0 TO N - 1
        LET  X(I) = S(J, I)
     NEXT I
     CALL HAAR (X, N, Y, MD)
     FOR I = 0 TO N - 1
        LET  S(J, I) = Y(I)
     NEXT I
  NEXT J
END SUB
 

戻る