## NAME

          btc_compress, btc_decompress -  2  level  Block  Truncation
         Coding (BTC) scheme

## SYNOPSIS

          #include <stdio.h>
          #include <string.h>
          #include "CVIPdef.h"
          #include "CVIPimage.h"
          #include "CVIPconvert.h"
          #include "block_trunc_coding.h"
          #include <sys/types.h>
          #include <sys/stat.h>

         int  btc_compress(Image  *inputImage,  char  *filename,  int
         blocksize)

          <inputImage> - pointer to an Image structure
          <filename> - character array
          <blocksize> - blocksize

         Image* btc_decompress(char *filename)

          <filename> - character array

## PATH

         $CVIPHOME/COMPRESSION/block_trunc_coding.c

## DESCRIPTION

         The image is first divided into blocks, and then the digital
         representation  of each pixel in a block is truncated to one
         bit by  thresholding  and  moment  preserving  selection  of
         binary levels.

         The function code was developed from  Chapter  5  Section  6
         "Block  Truncation  Compression"  (P176  - P181) in "Digital
         Picture Processing" Volume1, second edition,  Azriel  Rosen-
         feld  and  Avinash  C.  KakYiyan.  Academic  Press, INC. San
         Diego, CA. 1982

## TYPES AND CONSTANTS

         None

## RETURN VALUES

         btc_compress: 0 on success, -1 on failure

         btc_decompression:  an   uncompressed   image   pointer   on
         success,a NULL pointer on failure

## HISTORY

         History information recorded: None

## EXAMPLE

          #include "CVIPdef.h"
          #include "CVIPimage.h"
          #include "block_trunc_coding.h"
          #include "CVIPconvert.h"

          void main() {
            Image *cvipImage, *outImage;
            IMAGE_FORMAT format;
            char *inputfile, *outputfile;
            int blocksize;

            setDisplay_Image("picture", "Default");

            print_CVIP("\n\t\tEnter the Input File Name:  ");
            inputfile =(char *) getString_CVIP();
            cvipImage = read_Image(inputfile, 1);
            view_Image(cvipImage, inputfile);

            print_CVIP("\n\t\tEnter the block size:");
            blocksize = getInt_CVIP(10, 0, 64);
            print_CVIP("\n\t\tEnter the Compressed File Name:");
            outputfile =(char *) getString_CVIP();

            if (btc_compress(cvipImage,outputfile,blocksize)<0) {
              error_CVIP("btc_compress", "compression failed");
              exit(1);
            } else if ((outImage=btc_decompress(outputfile))==NULL){
              error_CVIP("btc_decompress", "decompression failed");
              exit(1);
            } else view_Image(outImage, outputfile);

            free(inputfile);
            free(outputfile);
          }

## BUGS

         For gray level images, the compression ratios are not calcu-
         lated correctly.

## SEE ALSO

         libcompress,       btc2_compress(),       btc2_decompress(),
         btc3_compress(), btc3_decompress()

## AUTHOR

         Copyright (C) 1996 SIUE - by Scott Umbaugh, Kui Cai.