Second Lab Work of IC Course
This repository contains two independent components:
- Golomb Coding — A C++ implementation of Golomb encoding/decoding for integers.
- Extract Color Channel — An OpenCV-based image utility to extract a single color channel.
Both can be built from the same Makefile using different targets.
On the root project directory, you can build everything or each target separately:
makemake extractmake golombmake image_codecThe binaries are placed inside the build/ directory:
build/golombbuild/extract_color_channelbuild/image_transformbuild/image_codec
./build/extract_color_channel <input_image> <output_image> <channel_index>Channel index (BGR):
0→ Blue1→ Green2→ Red
Example:
./build/extract_color_channel images-ppm/airplane.ppm airplane_red.pgm 2Create negatives, mirrors, rotate by multiples of 90°, and brightness changes.
Usage:
./build/image_transform <input> <output> <operation> [param]Operations:
neg— negativemirror_h— horizontal mirrormirror_v— vertical mirrorrotate <k>— rotate by k*90 degrees (k integer)bright <delta>— add delta to all channels (delta can be negative)
Examples:
./build/image_transform images-ppm/lena.ppm build/lena_neg.ppm neg
./build/image_transform images-ppm/lena.ppm build/lena_rot90.ppm rotate 1
./build/image_transform images-ppm/lena.ppm build/lena_bright_plus50.ppm bright 50You can encode or decode integer sequences using Golomb coding. Run with:
./build/golomb -m <m_value> -mode <mode> encode <list_of_integers>Parameters:
-
-m <m_value>→ the Golomb parameter (must be ≥ 1) -
-mode <mode>→ negative number handling mode:sign→ sign-and-magnitudeinterleave→ positive/negative interleaving (zig-zag)
Example (interleaved mode):
./build/golomb -m 3 -mode interleave encode 0 -1 5 10You can losslessly compress audio files into custom .glb format. Usage:
./golomb_codec encode input.wav output.glbor:
./golomb_codec decode output.glb output.wavLossless grayscale image codec based on spatial prediction and Golomb coding of prediction residuals. The tool expects a single-channel 8-bit image as input (PGM or grayscale PNG). If you start from a color image, extract one channel first (see Exercise 1).
Usage:
# Encode (mode must come first). Predictor: 0=left, 1=median (default=1)
./build/image_codec encode <input_gray> <output.gimg> [predictor]
# Decode to any image format supported by OpenCV (e.g., PNG)
./build/image_codec decode <input.gimg> <output_image>Notes:
- Input must be single-channel 8-bit; convert or extract a channel if needed.
- If you omit
encode/decodeas the first argument, you'll get "Unknown mode". - The encoder tries several
mvalues and prints the chosen parameter and bit count. - Decoding is lossless (pixel-by-pixel identical to the original input).
To remove the compiled binaries:
make clean-
The Makefile automatically checks for OpenCV via
pkg-config. If the OpenCV package isn’t found, you can specify one manually:make extract PKG=opencv
-
The Golomb module has no external dependencies and can always be built.