How to convert captured bitmap to 8 bit image as gray scale?

笑着哭i 提交于 2021-02-10 14:20:06

问题


I am trying to convert the camera captured image to 8 bit image. And that should be grayscale image.

I searched in forums but could able to find the way to convert to 8 bit image.

Any help or suggestion will be help ful to me.

Thanks....


回答1:


You have given too little information. First of all, what is the image format your camera delivers? Is it some RAW format, jpeg, or what else?

Doing it programmatically (using C for the example):

The best way to go was to use some image loading library (e.g. SDL_image), and load the image into memory, uncompressed RGB being the target format. Once you have an uncompressed RGB image format, you could do something like

// bufPtr points to the start of the memory containing the bitmap
typedef unsigned char byte;
struct rgb { byte red, green blue; } * colorPtr = bufPtr; 
for (int i = 0; i < bufSize; i++, bufPtr++) { 
   byte gray = (unsigned char) (((float) bufPtr->red * 0.3f + 
                                 (float) bufPtr->green * 0.59f + 
                                 (float) bufPtr->blue * 0.11f)) / 3.0f * 255.0f + 0.5f);
    bufPtr->red = bufPtr->green = bufPtr->blue = gray;
    }

If you don't want to code, you could e.g. use GIMP, load your image and apply desaturate from the color menu. You can install the ufraw plugin for GIMP to load images in RAW format in it. If you want to store the entire color information in 8 bits (and not use 8 bits per color channel), there is another option in GIMP to decrease the color depth.



来源:https://stackoverflow.com/questions/7138077/how-to-convert-captured-bitmap-to-8-bit-image-as-gray-scale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!