Coder Social home page Coder Social logo

rgbtogray's Introduction

Image Conversion from RGB to Grayscale

Overview

This C program takes an input BMP image file in RGB format and converts it into a grayscale image. The output is saved as a new BMP file. The program reads the header of the input image, extracts information such as width, height, and bit depth, and then performs the RGB to grayscale conversion on the image data.

Usage

  1. Compile the program using a C compiler. For example, using GCC:
    gcc your_program_name.c -o output_executable_name
  2. Run the compiled executable, providing the input and output file paths as command-line arguments.

Input

  • The input BMP file path is hard-coded in the program and set to "C:\\Users\\Poojitha Sai\\Downloads\\sample_bmp.bmp". Modify the path as needed.

Output

  • The output grayscale BMP file is saved with the file path "C:\\Users\\Poojitha Sai\\Downloads\\sample_bmp_output.bmp".

Code Explanation

  1. The program opens the input BMP file in binary read mode ("rb") and the output BMP file in binary write mode ("wb").
  2. It reads the 54-byte header from the input file and writes it to the output file.
  3. Extracts information from the header, including image width, height, and bit depth.
  4. Allocates a buffer to store the RGB data for each pixel in the image.
  5. Converts each pixel from RGB to grayscale using the formula gray = 0.3 * red + 0.59 * green + 0.11 * blue.
  6. Writes the resulting grayscale pixel values to the output file.

Note

  • The program assumes that the input image is in BMP format with a 24-bit color depth (8 bits per channel).
  • Refer this link to understand the conversion formula better.

Disclaimer

  • The program does not handle all possible BMP file formats or error conditions. It is a basic example and may need modifications for broader use cases.

rgbtogray's People

Contributors

pooji04 avatar

Watchers

 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.