Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Yulypso/Image-Processing-Tool

Repository files navigation

Image processing: Bitmap processing tool

Author

Linkedin: Thierry Khamphousone


Introduction

This project is about creating a tool that reads an image in a given format (bitmap or jpeg), process this image (enlarge, shrink ...), save the image in an output file different from the one given as input ( same format as input or different) to never corrupt the original files.


Note: This Bitmap Processing tool cannot process:

  • Due to RLE compression (Run length encoding)
    • bitmap v3
    • bitmap v5
    • bitmap v7
  • Due to bits per pixels < 8
    • bitmap v6
    • bitmap v7
    • bitmap v8

Table of Contents


Getting Started

Setup

> git clone https://github.com/Yulypso/Image-Processing-Tool.git
> cd Image-Processing-Tool
> python3 -m venv .venv
# for MacOs/Linux
> source .venv/bin/activate
#for Windows
> py -3 -m venv .venv
> .venv\scripts\activate
# to install requirements 
> pip3 install -r requirements.txt

Check Dependency Graph


Note: In Visual Studio Code, don't forget to select the correct Python interpreter.

[CMD + SHIFT + P] > select Interpreter > Python 3.9.0 64-bits ('.venv') [./.venv/bin/python]


Run the code

> cd project/bitmapProcessing
> python3 main.py [-h] --bmp <file_name.bmp> [--rotate <rotation degree>]
 [--overlay <file_name.bmp>, <option>][--blackwhite] 
 [--resize <resizing ratio> or [<width> <height>]] 
 [--verbose] [--flip] [--grayscale <grayscale method>] [--negative] 
 [--colorchannel <color channel>][--brightness <brightness value>]
 [--pixels <all> or [<position x> <position y>]] [--histogram] 
 [--contrast <contrast value>] [--filter <filter type>] 
 [--test_features] [--photomaton <split n time>] [--colorize <angle>]
 [--output <file_name.bmp>]
--Bitmap processing tool--
optional arguments:
 -h, --help show this help message and exit
 --bmp <file_name.bmp>
 image file to parse and displays header information
 --overlay, -ov <file_name.bmp>, <option>
 image file to overlay the input image, <maximum> or <minimum>
 --rotate, -rt <rotation degree>
 degree of image rotation [90, 180, 270]
 --resize, -rs <resizing ratio> or [<width> <height>]
 ratio of image resizing
 --contrast, -ct <contrast value>
 image contrast [-255, +255]
 --brightness <brightness value>, -bn <brightness value>
 image brightness [-255, +255]
 --verbose, -v get more information
 --flip, -fp image flip
 --grayscale, -gs <grayscale method>
 image grayscale <mean> or <luminance> or <atget>
 --negative, -n image negative
 --colorchannel, -cc <color channel>
 image color adjustment ['r', 'g', 'b', 'rg', 'rb', 'gb']
 --blackwhite, -bw image black & white
 --pixels, -p <display option> 
 display input image pixels <all> or [<position x> <position y>]
 --histogram, -hg display input image histogram
 --filter, -ft <filter type>
 image filter ['edge-detection', 'blur', 'edge-reinforcement', 'emboss']
 --photomaton, -ph <split n time>
 photomaton, split image by 4 n time
 --colorize, -cz <angle>
 colorize an image through its hue angle [0°, 360°]
 --test_features, -tf generate each feature
 --output, -o <file_name.bmp>
 generated file

Stop the code

#don't forget to deactivate the virtual environement (.venv)
> deactivate

Unit Test

> cd project/bitmapProcessing
> python3 unitTest.py
....
----------------------------------------------------------------------
Ran 4 tests in 0.000s
OK

Feature Implementations

To better understand the implementation of those features -> Click here


Feature Descriptions

We will mainly use Colored Lena to explain the features.


Dashboard

Each feature applied on the input bitmap has a checkbox to know easily which feature has been chosen

> python3 main.py --bmp lena_couleur.bmp --rotate 90 -hg -rs 400 400 -fp -ct +80 --pixels all -o generated.bmp -cc rb


Generate each feature within a test directory

Learn more about it

> python3 main.py --bmp lena_couleur.bmp --test_features


Display Bitmap header

Learn more about it

Display information inside the bitmap byte header

> python3 main.py --bmp lena_couleur.bmp


Display pixels

Display pixel colors at specific position, here x=128 and y=192

> python3 main.py --bmp lena_couleur.bmp --pixels 128 292

Display each bitmap pixel colors, here [ 55 81 158 ] is the first pixel value in the first row and first column of the matrix. (it refers to the real bitmap pixel at the last row and first column)

> python3 main.py --bmp lena_couleur.bmp --pixels all


Rotate image

Learn more about it

Rotate the bitmap to 90° or 180° or 270°

> python3 main.py --bmp lena_couleur.bmp --rotate 90 --output generated.bmp --verbose 


Resize image

Learn more about it

Resize the bitmap to a ratio value or specific dimensions

  • The bitmap has been resized to 256x256 with ratio value=0.5
> python3 main.py --bmp lena_couleur.bmp --resize 0.5 --output generated.bmp --verbose

  • The bitmap has been resized to dimension 500x300 (width x height)
> python3 main.py --bmp lena_couleur.bmp --resize 500 300 --output generated.bmp --verbose


Contrast adjustment

Learn more about it

Adjust the contrast parameter of the bitmap

> python3 main.py --bmp lena_couleur.bmp --contrast +180 --output generated.bmp --verbose
  • Negative adjustment (-255, -180, -80, -0)

  • Positive adjustment (+0, +80, +180, +255)


Color to grayscale

Learn more about it

Changes a colored bitmap into a grayscale image

  • With Eugène Atget sepia method
> python3 main.py --bmp lena_couleur --grayscale sepia --output generated.bmp --verbose

  • With mean method (average)
> python3 main.py --bmp lena_couleur --grayscale mean --output generated.bmp --verbose

  • With depending on luminance method (more accurate than mean method)
> python3 main.py --bmp lena_couleur --grayscale luminance --output generated.bmp --verbose


Color to black & white (binary)

Learn more about it

Changes a colored bitmap into a black and white image

> python3 main.py --bmp lena_couleur.bmp --blackwhite --output generated.bmp --verbose


Color to negative

Learn more about it

Changes a colored bitmap into a negative image

> python3 main.py --bmp lena_couleur.bmp --negative --output generated.bmp --verbose


Keep color channel

Learn more about it

Keep one-color or two-color channel of the bitmap

  • Red
  • Green
  • Blue
  • Red/Blue (Magenta)
  • Red/Green (Yellow)
  • Blue/Green (Cyan)
> python3 main.py --bmp lena_couleur.bmp --colorchannel rg --output generated.bmp --verbose


Brightness adjustment

Learn more about it

Adjust the brightness parameter of the bitmap

> python3 main.py --bmp lena_couleur.bmp --brightness +80 --output generated.bmp --verbose
  • Negative adjustment (-255, -180, -80, -0)

  • Positive adjustment (+0, +80, +180, +255)


Flip image

Learn more about it

Flip the bitmap along its vertical axis (along its horizontal axis is the same as a rotation 180°)

> python3 main.py --bmp lena_couleur.bmp --flip --output generated.bmp --verbose


Filter: Edge-detection

Learn more about it

filter to detect the edges of the image

> python3 main.py --bmp lena_couleur.bmp --filter edge-detection --output generated.bmp --verbose


Filter: Edge-reinforcement

Learn more about it

filter to reinforce the edges of the image

> python3 main.py --bmp lena_couleur.bmp --filter edge-reinforcement --output generated.bmp --verbose


Filter: Blur

Learn more about it

filter to blur the image

> python3 main.py --bmp lena_couleur.bmp --filter blur --output generated.bmp --verbose


Filter: Emboss

Learn more about it

filter to emboss the image

> python3 main.py --bmp lena_couleur.bmp --filter emboss --output generated.bmp --verbose


Color channel Histogram

Display color channel histogram

> python3 main.py --bmp lena_couleur.bmp --histogram --output generated.bmp --verbose
  • Color channel histogram for colored image

  • Color channel histogram for grayscale image


Overlay two images

Learn more about it

Feature to superimpose one image to another

  • The output image is generated by obtaining the darkest pixel between the two images
> python3 main.py --bmp lena_couleur.bmp --overlay generated/bitmap512-512.bmp maximum --output generated.bmp --verbose

  • The output image is generated by obtaining the lightest pixel between the two images
> python3 main.py --bmp lena_couleur.bmp --overlay generated/bitmap512-512.bmp minimum --output generated.bmp --verbose


Image colorization

Learn more about it

Image colorization is mainly used to add color on grayscale images.

> python3 main.py --bmp lena_sepia.bmp --colorize 180 --output generated.bmp --verbose
  • Colorization hue angle: 0°/360°, 45°, 90°, 135°

  • Colorization hue angle: 180°, 225°, 270°, 315°


Photomaton

Learn more about it

The photo booth or Photomaton is used to get several identical images in a whole image

> python3 main.py --bmp lena_sepia.bmp --photomaton 1 --output generated.bmp --verbose



Fun zone

AltStyle によって変換されたページ (->オリジナル) /