Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C language to realize bmp Image contrast extension

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to use C language to achieve bmp image contrast expansion". In daily operation, I believe many people have doubts about how to use C language to achieve bmp image contrast expansion. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubt of "how to use C language to achieve bmp image contrast expansion". Next, please follow the editor to study!

Suppose there is a picture in which the whole image is dimmed due to insufficient imaging time (for example, the gray range is from 0 to 63), or the imaging time is too strong to make the whole image brighter (for example, the grayscale range is from 200 to 255). We call these cases low contrast, that is, the grayscale are all squeezed together and not pulled apart. The meaning of grayscale expansion is to open the grayscale range of your sexual interest, so that the brighter the pixels in this range, the darker they are, so as to enhance the contrast.

The Abscissa gold in the figure represents the gray value of the original image, and the ordinate gnew indicates that the gold gets a new gray value after the contrast expansion. The slope of the three straight lines is b > 1 because it is the expansion of the contrast. G1old and g2old represent the range of contrast expansion in the original image, and g1new and g2new represent the corresponding new values. Expressed by a formula as follows:

Implementation code:

# include#include#include#pragma pack (1) / / fully compact mode typedef struct {unsigned char bfType [2]; unsigned int bfSize; unsigned short bfReserved1; unsigned short bfReserved2; unsigned int bfOffBits;} bitmapFileHeader;typedef struct {unsigned int biSize; unsigned int biWidth; unsigned int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; unsigned int biXPixPerMeter; unsigned int biYPixPerMeter; unsigned int biClrUsed; unsigned int biClrImportant;} bitmapInfoHeader;typedef struct {unsigned char rgbBlue; unsigned char rgbGreen; unsigned char rgbRed; unsigned char rgbReserved;} rgbQUAD;typedef struct {bitmapFileHeader bfHeader; bitmapInfoHeader biHeader RgbQUAD palette; unsigned char * imgData;} bmp;int main () {FILE * fp; if ((fp=fopen ("d:\ Temp\\ test_gray.bmp", "rb")) = = NULL) {perror ("can not open file!"); return-1;} / / read in the color bmp image header, information header and image data bitmapFileHeader bfHeader; fread (& bfHeader,14,1,fp); bitmapInfoHeader biHeader; fread (& biHeader,40,1,fp); int imSize=biHeader.biSizeImage; int width=biHeader.biWidth; int height=biHeader.biHeight Int bitCount=biHeader.biBitCount; int lineBytes= (width*bitCount+31) / 3234; fseek (fp,bfHeader.bfOffBits,SEEK_SET); unsigned char*imageData= (unsigned char*) malloc (imSize*sizeof (unsigned char)); fread (imageData,imSize*sizeof (unsigned char), 1je FP); fclose (fp); bmp b; memcpy (& (b.bfHeader), & bfHeader,sizeof (bfHeader)); memcpy (& (b.biHeader), & biHeader,sizeof (biHeader); b.imgData= (unsigned char*) malloc (sizeof (unsigned char) * imSize)) Memset (b.imgDataMagne0Magnesizeof (unsigned char) * imSize); for (int item0witi)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report