473,406 Members | 2,867 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,406 software developers and data experts.

How to remove one color in a image.

Hi guy's

I am working on a sprite game in c++ and OpenCV. I have created to images, the backgroundimage (the background image in the game and the spriteman (my character in the game).

How do I remove the colour blue colour around my character?

Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.  
  3. // Loading Images - Loading the Background Image
  4. IplImage* backgroundimage = cvLoadImage("mission11.png"); 
  5. backgroundimage->width;
  6. backgroundimage->height;
  7.  
  8. // Creating an empty images - Setting the widt and height values as backgroundimage
  9. IplImage* temp = cvCreateImage(cvSize(backgroundimage->width,backgroundimage->height),IPL_DEPTH_8U,3) ;
  10.  
  11. // Loading Images - Loading the Sprite Image
  12. IplImage* spriteman = cvLoadImage("spriteman.jpg"); //change the file name with your own image
  13. spriteman->width;
  14. spriteman->height;
  15.  
  16. // The start place of the sprite 
  17. int placeY = 80;
  18. int placeX = 80;
  19.  
  20. // Creating a variable for the keys ind the game
  21. char presskey;
  22.  
  23. // The start place of the sprite
  24. bool run = true;
  25.  
  26. while(run){
  27.  
  28.     char presskey = cvWaitKey(5);
  29.  
  30.     switch(presskey) {
  31.     case 'w':
  32.     case 38:
  33.         placeY -=10;
  34.         break;
  35.     case 'a':
  36.     case 39:
  37.         placeX -=10;
  38.         break;
  39.     case'd':
  40.     case 40:
  41.         placeX +=10;
  42.         break;
  43.     case's':
  44.     case 41:
  45.         placeY +=10;
  46.         break;
  47.     case 32:
  48.         placeY -=20;
  49.         break;
  50.     case'q':
  51.     case 27:
  52.         run=false;
  53.         break;
  54.     }
  55.  
  56.     for(int i=0;i<backgroundimage->height*backgroundimage->width*backgroundimage->nChannels;i++){
  57.         temp->imageData[i]=backgroundimage->imageData[i];
  58.     }
  59.     for(int y = 0; y < spriteman->height; y++){
  60.         for(int x = 0; x < spriteman->width; x++){
  61.             for(int z = 0; z < spriteman->nChannels; z++){
  62.                 if(((uchar *)(spriteman->imageData + y*spriteman->widthStep))[x*spriteman->nChannels + z] < 260){
  63.                     temp->imageData[(y + placeY) * backgroundimage->widthStep + (x+placeX) * backgroundimage->nChannels + z] = spriteman->imageData[y * spriteman->widthStep + x * spriteman->nChannels + z];
  64.  
  65.                 }
  66.  
  67.             }
  68.         }
  69.     }
  70.  
  71.     // Display the image temp
  72.     cvShowImage("Metal Slug: Kill Rambo", temp);
  73. }
  74.  
  75. //create a new window with  
  76. cvNamedWindow("Metal Slug: Kill Rambo", CV_WINDOW_FULLSCREEN);
  77.  
  78.  
  79. //Destroying the Window and the Images within
  80. cvDestroyWindow( "Metal Slug: Kill Rambo" );
  81. cvReleaseImage( &backgroundimage );
  82. cvReleaseImage( &temp );
  83. cvReleaseImage( &spriteman );
  84. return 0;
  85.  
  86. }
  87.  
Oct 11 '10 #1
1 3654
Hi,
You are using a png image, so i assume that u r image is 32-bit and ARGB pixel format.

All you have to do is check for each pixel color and if it matches 0xff0000ff than replace it with 0x00000000, so that blue color in the image vil become transparent.

To get more help on web search for color keying algorithm.

Hope this helps.
Oct 12 '10 #2

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

Similar topics

3
by: Jeremy Bowers | last post by:
I have an image in the Python Image Library. I'm trying to get it into PyGTK in color. Is there any way to do this cross-platform, preferably without writing to anything to the disk? PIL...
2
by: DanS | last post by:
Does anyone know how to change an image from color to black and white / greyscale programmatically in c#? Nothing in the image or bitmap objects looked promising? thanks!
2
by: Mohammad | last post by:
Hello. How I can write a program that save a high color image as 256 color or fewer with .BMP format , just like Microsoft Paint. I want to write this Program with C# .NET , NOT with MFC . Thank...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
2
by: Ira | last post by:
Is it possible to convert a 32-bit color image into a 1-bit-per-pixel image in VB.net? If yes, how can it be done?
3
by: ShihChengYu | last post by:
Dear all: How to convert color image to bi-level image? I have confronted one problem when I build my OCR project. I used an software API function to enhance my project, but the API only...
1
by: Sugan | last post by:
Hi all, I'm creating a custom button control. I need to show a color image when the button control is enabled and a gray shade of the same image when the button control is disabled. How can i...
1
by: donandreone | last post by:
16 bit - 565 (5 bits for the red,6 for green and 5 for blue). Assume that the source bitmap was already loaded in in one buffer - bmpBuf with pixel format 332 (3 bits for red, 3 for green and 2 for...
3
by: Muddasir | last post by:
hi all i need to upload an image and if that image is coloured i need to convert it to black and white image ... till now i only uploaded images ... simple.. have no idea how to do this...
19
mb60
by: mb60 | last post by:
sir I created a multiple choice questions data bank in ms access. some questions have images. in the report blanks gaps are appearing when the question is without image. please help me in this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.