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 7075173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:08:45+00:00 2026-05-28T06:08:45+00:00

I have a grayscale image that needs to be painted with values from a

  • 0

I have a grayscale image that needs to be painted with values from a gradient of 5 colors. Light pixels should get a lighter color from the gradient, dark pixels should get a darker one.

If the gradient starts with yellow and ends with red, then white pixels would be yellow and black pixels red with everything in between along the gradient.

Can it be done with ColorMatrix?

  • 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-28T06:08:46+00:00Added an answer on May 28, 2026 at 6:08 am

    What you want is in the simplest case a linear interpolation between 5 points in 3d. A direct color gradient between two colors {r1,g1,b1} and {r2,g2,b2} is, as you would walk onto the line in 3d which connects the points {r1,g1,b1} and {r2,g2,b2}.
    When your gray-values are in the interval [0,1], then you would want to have the color {r1,g1,b1} if you have a gray-level 0 and {r2,g2,b2} if you have a gray-level 1. The question is how to calculate the colors in between:

    think of the simple school vector analysis. c1 is the point {r1,g1,b1}, c2 is {r2,g2,b2}. Start at c1 and go in direction of the vector c2-c1:

    outColor = c1 + gray*(c2-c1)

    or equivalently

    outColor = (1-gray)c1 + grayc2

    Remenber, gray must lie in the interval [0,1]. Otherwise you have to rescale it. This is simple linear interpolation between two points which can of course be extended for as many colors as you want.

    For five colors the approach is basically the same. Here for 5 randomly chosen colors:

    {{0.273372, 0.112407, 0.0415183}, 
     {0.79436,  0.696305, 0.167884}, 
     {0.235083, 0.999163, 0.848291}, 
     {0.295492, 0.780062, 0.246481}, 
     {0.584883, 0.460118, 0.940826}}
    

    enter image description here

    Two important things you have to know:

    1. If you want to have the color for a given gray-value, you first need to extract the two surrounding rgb-points. For instance if you want to have the color for gray=0.1 it would be the first and the second rgb-point.

    2. You have to rescale your gray-value according to the number of colors which you use in your gradient. Look at the image, with 5 colors, you have 4 different two point interpolation intervals. When you want to make the above mentioned color formula work, you have to rescale your gray-value for each color-interval to [0,1].

    Remark: This is of course not the solution for the implementation in C#, but your question suggested, that creating a color-image of the same size was not your problem. Calculating the color-values for each gray-value is the key for your colorization.

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

Sidebar

Related Questions

I have a 16 bit grayscale image that I want to display using WPF
I have 1 Bitmap image and i had converted that image into grayscale. My
Imagine you have two images A and B, and a third grayscale image T.
I have an int array containing gray scale values from 0-254, i also have
I need to create a grayscale image from data in an nio ShortBuffer. I
A have a struct with four very large matrices that correspond to grayscale images.
I have a grayscale icon that I'm editing with Photoshop with a transparent background,
I have a UIImage that is displaying a grayscale button. Is there a way
I have a texture which has only 1 channel as it's a grayscale image.
I have a gif image which is way too big for my needs (even

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.