Skip to content

team3997/greyscale-11-w1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

greyscale

Converting an Image to Grayscale by Skye McClenny, Michael Chacko, Lucy Zhao

This program is designed to work only with 24-bit bmp files!

[Background] To handle the problem of storing digital images, two major file format types are used: raster and vector. While raster graphics break an image into its individual pixels and stores their information in a dot-matrix structure, vector graphics represent an image in terms of geometric components that can be resized and rendered smoothly at any resolution. In our program, we decided to work with the former family of file types, as it is the most commonly encountered in day-to-day life and closer to most people’s conception of how digital images are stored.

Our program is designed to input a bitmap image file (BMP), process the individual pixels to apply a “grayscale” filter, and output a new, converted bitmap. We chose to work with this file type because not only is it the most lauded image format for being uncompressed and therefore lossless, the majority of BMP files have the same simple, versatile structure, stored in binary. Most BMP formats have a 54 byte header which contains information about the image file itself (file size, width, height, etc...). After the header information, the pixel data for the image is stored as RGB values, with each row of values corresponding to a different row of pixels.

To access the BMP being converted, the file must first be imported. In C, this can be done by declaring a pointer and assigning to it the path of the BMP. Using the fread() function, the header is read and each component is stored to a variable, to be later written, unaltered, to the converted file. Next, an array is created with enough memory allocated for the image’s amount of pixels as denoted by the header. The fread() function is used again to copy the pixel data from the original BMP to the array. It is then possible to loop through the array and make any changes desired to the RGB values, effectively applying a “filter”. In this instance, to convert the image to grayscale, the average of the RGB values of each pixel is computed, and then each array element storing the RGB values of the pixel is set to the average.

To output the converted pixels in a different BMP, a new file is created using the fopen() method and its path is assigned to a pointer for access. The previously stored header information is then written to the file first, as without this crucial piece of information, an image reader would be unable to recognize the type of file it has encountered. The converted pixel data array is then written to the new file. To complete the conversion process, both the input and output files are closed afterwards, and the new BMP path is printed to the console.

About

Make a greyscale image 11/1/2015

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages