user1227372
user1227372

Reputation: 35

pixel conversion to raw bits (bit-stream)

I want to read the contents of every pixel in an image i have and convert it to a bit-stream (raw bits) or contain it in a 2-D array . Which would be the best place to start looking for such a conversion?

Specifics of the image : Standard test image called lena.bmp size : 256 x 256 Bit depth of pixel : 8

Also I would like to know the importance of the number of bits per pixel with regards to this question since packing and unpacking will also be incorporated .

Upvotes: 1

Views: 1958

Answers (2)

Stack Overflow is garbage
Stack Overflow is garbage

Reputation: 248199

CImg is a nice simple, lightweight C++ library which can load and save a number of image formats (including BMP).

It's a single header file, so there's no need to compile or link the library. Just include the header, and you're good to go.

Upvotes: 4

karlphillip
karlphillip

Reputation: 93468

You should investigate OpenCV: a cross-platform computer vision library. It provides a C++ API as well as a C API, and it supports many image formats including bmp.

In the C++ interface, cv::Mat is the type that represents a 2D image. A simple application that loads and displays an image can be found here.

To learn how to access the matrix elements (pixels) you can check these threads:

OpenCV’s C++ interface offers a short introduction to cv::Mat. There has been many threads on Stackoverflow regarding OpenCV, there's a lot of valuable content around and you can benefit a lot by using the search box.

This page has a collection of books/tutorials/install guides focused on OpenCV, but this the newest official tutorial.

Upvotes: 2

Related Questions