Skip to content

Repository files navigation

CSCI-576 Assignment 1: Image Scaling and Quantization

A C++/wxWidgets desktop application that reads a raw 512x512 RGB image, scales it down by a given factor, quantizes the result, and displays the output in a scrollable window.

Built on the cross-platform ImageDisplay_C++_cross_platform starter code provided with the course. All assignment work lives in src/Main.cpp.

Input format

The application expects a headerless .rgb file containing 512x512 pixels stored plane by plane: all red bytes, then all green bytes, then all blue bytes. Sample images are in sample_images/, each with a .png preview alongside the .rgb data.

Usage

./MyImageApplication <image.rgb> <scale> <Q> <M>

scale is the downscaling factor, between 0.0 and 1.0, applied to both dimensions.

Q is the total bits per pixel: 1 to 24, and a multiple of 3. Each channel gets Q/3 bits, giving 2^(Q/3) levels per channel.

M selects the quantization mode. M = -1 is uniform quantization, M from 0 to 255 is logarithmic quantization, and M = 256 is optimal interval quantization.

Example:

./MyImageApplication ../sample_images/Lena_512_512.rgb 0.5 12 -1

Arguments are validated at startup; the program exits with a message if any value is out of range.

Implementation

Scaling: for each pixel in the output image the corresponding source coordinate is computed from the scale factor, and a 3x3 average kernel is applied around it, so the downsampled image is filtered rather than point-sampled. Kernel taps falling outside the image are skipped and the average is taken over the remaining taps.

Uniform quantization splits the 0-255 range into 2^(Q/3) equal intervals and maps every pixel to the midpoint of its interval.

Logarithmic quantization treats M as a pivot. Each pixel's distance from the pivot is normalized against the available range on its side, compressed with mu-law companding (mu = 255), quantized in the compressed domain, then expanded back and offset by the pivot. This gives finer intervals near the pivot and coarser ones far from it.

Optimal interval quantization uses Lloyd's algorithm. Centroids start at the midpoints of uniform intervals, then are repeatedly reassigned to the mean of the pixels nearest to them until they stop changing. Each pixel is then replaced by its nearest final centroid.

Quantization runs on the scaled image, over all three channels treated as a single byte stream.

Results

Test image 4, scale 1.0, Q = 12, under each quantization mode.

Uniform (M = -1) Logarithmic (M = 128) Optimal (M = 256)

Build

See BUILD.txt for the full setup and build instructions from the starter code. wxWidgets is vendored under dependency/ and built as part of the project, so no separate install is needed. The executable is written to build/MyImageApplication.

One deviation from those instructions: the starter code shipped with cmake_minimum_required(VERSION 3.1) in CMakeLists.txt and VERSION 3.0 in dependency/wxWidgets/CMakeLists.txt, both rejected by recent CMake releases. Both have been raised to 3.5 here, so no manual patching is needed.

Layout

src/             Main.cpp — all assignment code
dependency/      vendored wxWidgets
manifest/        Windows application manifest
sample_images/   512x512 .rgb test images with .png previews
CMakeLists.txt   build script
BUILD.txt        starter-code setup and build instructions

About

A C++/wxWidgets desktop application that reads a raw 512x512 RGB image, scales it down by a given factor, quantizes the result, and displays the output in a scrollable window.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages