Giter VIP home page Giter VIP logo

tga-image-resize's Introduction

TGA image resizing by half implementation

Table of Contents
  1. Introduction
  2. Background
  3. System Design
  4. Usage
  5. Contact

Introduction

The main scope of this project is implementing a command-line tool in C++ language that resizes a given TGA image by half of the original dimensions. In the following sections, a brief background for the TGA image format and the resizing algorithm will be explained. After that, the system design section will highlight design decisions.

Background

TGA Image Format

Truevision TGA, TARGA, the image format was created by Truevision Inc. in the early '80s. The format can store image data with 8, 15, 16, 24, and 32 bits of precision per pixel. Color data can be stored as color mapped or true color data. In addition, image data could be stored as raw bytes, or as a compressed byte which is encoded by RLE. According to the TGA specification a TGA image file is composed of 18 bytes header section which stores the image data properties, and a color map and image data section depending on the image type. As it can be seen from the specification, there are 6 different image types; uncompressed grayscale, color mapped, RGB images and compressed grayscale, color mapped, RGB images. In the scope of this project, compressed RBG, compressed grayscale, uncompressed RGB, and uncompressed grayscale images will be handled.

Half-sizing Algorithm

To reduce to image size by half in each dimension, it is required to apply a resampling algorithm to the image. One of the simplest algorithms for downscaling is Nearest-neighbor interpolation. In basic terms, nearest-neighbor interpolation will only take closes pixel value and average it with the current pixel value. For example, if we think of the following image as a simple 4x4 image, arrows on the image are denoting pixels are taken into account if the nearest-neighbor interpolation is applied.

Nearest-neighbir

However, as it can be deducted from the image algorithm is ignoring all the adjacent pixels, and will simply output a poorly reduced image as a result. Therefore, it is decided to use another resampling algorithm for downscaling which will provide better quality, and also will be not computationally expensive. As a result, Bilinear interpolation is selected as a resampling algorithm in the project. Bilinear interpolation considers the closest 2x2 neighborhood of known pixel values to calculate the average pixel value. Since we aim to reduce the image size by half, we are only interested in every alternating pixel value. It can be depicted in the following image by using the previous example again.

Bilinear Interpolation

System Design

Architecture

Since the project's scope is to reduce a given Targa image size by half, it will be helpful to separate the image reading and writing part from the image processing. The designed system consist of three subsystems which can be listed as follows:

- Decoder: Reads the Targa image file and populates the necessary fields.
- Image Processor: Applies half-sizing algorithm.
- Encoder: Constructs a Targa image file and writes it to the disk.

Diagrams

The UML class and sequence diagram of the designed system is given in the following pictures.

Class Diagram

Sequence Diagram

Usage

The project is implemented in C++ and considers portability as a first principle. Therefore, it is possible to use it on any operating system.

Prerequisites

  • C++17 supporting compiler
  • CMake 3.2 or above

Installation

After unzip or cloning the project to a directory, simply apply the following steps:

For Linux/Mac OS:

  • mkdir build & cd build
  • cmake ..
  • make & make install
  • cd ../bin & ./halfsize <imagefile.tga>

Contact

Ozan Tanfener - [email protected]

tga-image-resize's People

Contributors

otanfener avatar

Stargazers

Roman avatar

Watchers

 avatar  avatar Mehmet Onur Aybek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.