Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6150689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:39:10+00:00 2026-05-23T19:39:10+00:00

I have a basic png file with two colors in it, green and magenta.

  • 0

I have a basic png file with two colors in it, green and magenta. What I’m looking to do is to take all the magenta pixels and make them transparent so that I can merge the image into another image.

An example would be if I have an image file of a 2D character on a magenta background. I would remove all the magenta in the background so that it’s transparent. From there I would just take the image of the character and add it as a layer in another image so it looks like the character has been placed in an environment.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:39:11+00:00Added an answer on May 23, 2026 at 7:39 pm

    That’s the code i would use,

    First, load your image :

    IplImage *myImage;
    myImage = cvLoadImage("/path/of/your/image.jpg");
    

    Then use a mask like this to select the color, you should refer to the documentation. In the following, I want to select a blue (don’t forget that in OpenCV images are in BGR format, therefore 125,0,0 is a blue (it corresponds to the lower bound) and 255,127,127 is blue with a certain tolerance and is the upper bound.
    I chose lower and upper bound with a tolerance to take all the blue of your image, but you can select whatever you want…

    cvInRangeS(image, 
               cvScalar(125.0, 0.0, 0.0), 
               cvScalar(255.0, 127.0, 127.0), 
               mask
               );
    

    Now we have selected the mask, let’s inverse it (as we don’t want to keep the mask, but to remove it)

    cvNot(mask, mask);
    

    And then copy your image with the mask,

    IplImage *myImageWithTransparency; //You may need to initialize it before
    cvCopy(myImage,myImageWithTransparency,mask);
    

    Hope it could help,

    Please refer to the OpenCVDocumentation for further information

    Here it is

    Julien,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic PHP question, take the code below for example, let's say
I have basic idea on Kilo Virtual Machine on Mobiles , I have clear
I have basic hello word example of Prime Faces. I have created dynamic web
I have a basic class that derived subclasses inherit from, it carries the basic
I have a basic question, in the Django template language how can you tell
I have the basic code to rewrite a subdomain to another page. But how
I have a basic has_many :through relationship that is bi-directional: calendars have many calendar_calendar_events
I have a basic string with holds a html table. The table looks like
I have some basic questions around understanding fundamentals of Performance testing. I know that
I have a basic div element to represent a message that I show for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.