473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Urgent-reading bitmap images in c++, kindly help

guys,

I really want to know how i can process images in c++ (.bmp)
Dec 11 '06 #1
7 7171
sivadhas2006
142 100+
guys,

I really want to know how i can process images in c++ (.bmp)
Hi,

What is the process you want to do with the bmp images?
For eg., display the bmp image

Also check this link.

Read BMP Images


Regards,
M.Sivadhas.
Dec 11 '06 #2
macklin01
145 100+
Hi,

What is the process you want to do with the bmp images?
For eg., display the bmp image

Also check this link.

Read BMP Images


Regards,
M.Sivadhas.
You can use my open source C++ bitmap library (EasyBMP) to read, modify, and write bitmap images. Here's a sample (to invert the colors, as in a photograph negative):

Expand|Select|Wrap|Line Numbers
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. #include "EasyBMP.h"
  8.  
  9. int main( int argc, char* argv[] )
  10. {
  11.  if( argc < 3 )
  12.  {
  13.   cout << "Correct usage: InvertColors <input.bmp> <output.bmp>" << endl;
  14.   return -1;
  15.  }
  16.  
  17.  // declare and read the image
  18.  
  19.  BMP Image;
  20.  Image.ReadFromFile( argv[1] );
  21.  
  22.  // do operations on the pixels
  23.  
  24.  for( int j=0; j < Image.TellHeight() ; j++ )
  25.  {
  26.   for( int i=0; i < Image.TellWidth() ; i++ )
  27.   {
  28.    Image(i,j)->Red   = 255 - Image(i,j)->Red;
  29.    Image(i,j)->Green = 255 - Image(i,j)->Green;
  30.    Image(i,j)->Blue  = 255 - Image(i,j)->Blue;
  31.   }
  32.  }
  33.  
  34.  // write the modified image
  35.  
  36.  Image.WriteToFile( argv[2] );
  37.  
  38.  return 0;
  39. }
  40.  
1, 4, 8, 16, 24, and 32 bits per pixel are supported. It's also a cross-platform/cross-compiler library.

Please post here if you have additional questions. Thanks -- Paul
Dec 12 '06 #3
Hi,

I've been trying to flip a bmp image vertically through the center of the image but i dont think im doing it right.

i have so far

BMP img;

img.ReadToFile("in.bmp");

int width = img.TellWidth();
int height = img.TellHeight();

for(int i=0; i<width; i++){
for(int j=0; j<height; j++){
img(i,j)->Red = img(j,i) ->Red;
img(i,j)->Green = img(j,i) ->Green;
img(i,j)->Blue = img(j,i) ->Blue;
}
}

img.WriteToFile("out.bmp");

I dont have any idea on how to adjust the brigthness of an image, any help will be greatly appreciated.

Thanks in advance for your help.
Feb 6 '10 #4
macklin01
145 100+
Hi, Bryant.

In the code above, you are overwriting the pixels of img as you go, which means that you will lose half the image before you finish.

Instead, make a second, blank image, say:

BMP blank;
blank.SetSize( img.TellWidth() , img.TellHeight() );

Then, use your same code, only with "img" as the source and "blank" as the destination.

As for brightness balance, that's something you would need to code yourself, because EasyBMP is solely for reading and writing pixels -- it's up to you to decide what to do to them. :-)

However, I have done the following simple "normalization":

ebmpBYTE max_Red = 0;
ebmpBYTE max_Green = 0;
ebmpBYTE max_Blue = 0;

for( int i = 0 ; i < img.TellWidth() ; i++ )
{
for( int j=0 ; j < img.TellHeight() ; j++ )
{
if( img(i,j)->Red > max_Red )
{ max_Red = img(i,j)->Red; }
// similar for red and green.
}
}

ebmpBYTE red_adjust = 255 - max_Red;
// similar for green_adjust, blue_adjust

for( int i=0; i < img.TellWidth() ; i++ )
{
for( int j = 0 ; j < img.TellHeight() ; j++ )
{
img(i,j)->Red += red_adjust;
// similar for green, blue.
}
}

Depending upon the image, that may or may not do the trick, but is a nice start. More advanced ways would be to convert the image to a HSL or HSV color space and do computations on L (lightness) or V (value), but that's a rather bit more complex.

Another alternative:

Just go through and calculate "max_lightness" like this:

double max_lightness = 0;
// loop over all pixels

double temp_lightness = 0.3 * img(i,j)->Red + 0.59 * img(i,j)->Green + 0.11 * img(i,j)->Blue;
if( temp_lightness > max_lightness )
{ max_lightness = temp_lightness; }

// then loop over all pixels again and rescale the image such that
// the max lightness is 255.0

double temp_lightness = 0.3 * img(i,j)->Red + 0.59 * img(i,j)->Green + 0.11 * img(i,j)->Blue;

double temp_red = img(i,j)-Red * ( 255.0 / temp_lightness );
img(i,j)-> = (ebmpBYTE) ( temp_red );
// similar for green and blue

The effect should be to change the maximum lightness to 255 while maintaining the same relative difference between all the pixels. Both methods are probably worth examining.

You might want to add a "rounding" or "floor" type of operation prior to the last (ebmpBYTE) conversion.

I hope that helps. -- Paul
Feb 6 '10 #5
hi Paul,

Thanks so much for the detailed response.
One of the major requirement is that i should not declare a blank image. the requirement is as follow:

"flip a image about a vertical line through its center by swapping pixels

You must implement this function with space efficiency. That is, you should not declare a new empty Image into which you copy pixels. Rather, you should just use a temporary variable to swap pixels within the original Image"

I am to alter an already existing image. i cant create a blank image and copy an image to it pixel by pixel.

than you so much for your help. I hope you have the time to help me more
bryant
Feb 7 '10 #6
macklin01
145 100+
Ah, I see. Good point.

Something like this, then:

// loop over all pixels
RGBApixel temp = *img(i1,j1);
*img(i1,j1) = *img(i2,j2);
*img(i2,j2) = temp;

// or like this
// loop over all pixels

BYTE temp = img(i1,j1)->Red;
img(i1,j1)->Red = img(i2,j2)->Red;
img(i2,j2)->Red = temp;
// repeat for green, blue, alpha

The latter is more tedious but takes 3 bytes less memory (:rolleyes:).
Feb 7 '10 #7
You are the best. Thanks a lot. I'll implement this and will let you know if I'm having more problems. Please be online tomorrow also, if you have the time.

Thanks Paul.

Bryant.
Feb 7 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Johnson Ndiovu | last post by:
This is a multi-part message in MIME format --af4b847f-30bf-4b8d-acf1-2909de953a6e Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable DEAR FRIEND, ...
1
by: Heros | last post by:
I had losed my serial key for .net Visual Studio Professional, DVD ROM with the trial version, 60 days, and need urgent to use it to install .net Visual Basic. Please, its urgent. Thanks.
5
by: VbUser25 | last post by:
hi i need urgent responses.. i have some 15 checkboxex on a form... i want to 1st check the no. of checkboxes that are checked?? and then loop it that many times adn insert the quantities the...
3
by: Rob | last post by:
I have a form - when you click the submit button, it appends a variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable) It also opens a new page. Now, that some_dynamic_variable is...
9
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
3
by: gani | last post by:
hi, how to get the fullpath of created IsolatedStorage directory. thanks. -- gani
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
1
by: samir dsf | last post by:
hi this is kinda urgent ... i will insert some data in html format..i just need to know how to disply it back.its urgent...so if anyone can suggest pls tell me i simply need to know that if i...
4
by: EricJ | last post by:
the click event of a picturebox gives an e As System.EventArgs but this e dousnt contain xy coordinates of the click (and yes i need those :/) Private Sub picSchade_Click(ByVal sender As...
7
by: Cirene | last post by:
I used to use the Web Deployment Project with my VS2005 projects. Now I've fully upgraded to VS2008. Do I have to download a new version of the Web Deployment Project? If so where can I find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.