guys,
I really want to know how i can process images in c++ (.bmp)
7 7171
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.
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): -
#include <cstdio>
-
#include <cstdlib>
-
#include <iostream>
-
-
using namespace std;
-
-
#include "EasyBMP.h"
-
-
int main( int argc, char* argv[] )
-
{
-
if( argc < 3 )
-
{
-
cout << "Correct usage: InvertColors <input.bmp> <output.bmp>" << endl;
-
return -1;
-
}
-
-
// declare and read the image
-
-
BMP Image;
-
Image.ReadFromFile( argv[1] );
-
-
// do operations on the pixels
-
-
for( int j=0; j < Image.TellHeight() ; j++ )
-
{
-
for( int i=0; i < Image.TellWidth() ; i++ )
-
{
-
Image(i,j)->Red = 255 - Image(i,j)->Red;
-
Image(i,j)->Green = 255 - Image(i,j)->Green;
-
Image(i,j)->Blue = 255 - Image(i,j)->Blue;
-
}
-
}
-
-
// write the modified image
-
-
Image.WriteToFile( argv[2] );
-
-
return 0;
-
}
-
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
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.
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
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
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:).
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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,
...
|
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.
|
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...
|
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...
|
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...
|
by: gani |
last post by:
hi,
how to get the fullpath of created IsolatedStorage directory.
thanks.
--
gani
|
by: Tamir Khason |
last post by:
Follwing the struct:
public struct TpSomeMsgRep
{
public uint SomeId;
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| | |