Jump to content

How do I change a region's RGB or HSV values by a certain amount?


Recommended Posts

Greetings,

 

How can I increase or decrease the RGB or HSV values of a group of pixels in a selected area by the same amount? For instance, I need to increase one region's brightness by 17 on the HSV scale to make it match another region; however, neither the Brightness / Contrast tool, nor the Hue / Saturation tool seem to increase or decrease these values by any calculation that I can thus far figure out (I apologize in advance if the answer is simple; I've been at this for over 16 hours). Much of my work has thus been trial and error to find the right amount to increase or decrease these values using the provided tools. Is there a formula or plugin I can use?

 

Thank You.

Link to comment
Share on other sites

16 hours ago, lightknight said:

How can I increase or decrease the RGB or HSV values of a group of pixels in a selected area by the same amount?

 

I recommend using CodeLab for something like this.

 

Here is a list of tutorials to get you started: https://boltbait.com/pdn/CodeLab/help/

 

Tutorial 2 includes instruction on how to modify the R, G, and B values independently.

 

As for V, take a look at this script:

 

// Force Aliased Selection
#region UICode
IntSliderControl Amount1 = 0; // [-100,100] Adjustment
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    // Look at each row of your selection
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        // Look at each pixel on that row
        for (int x = rect.Left; x < rect.Right; x++)
        {
            // Look at the current pixel
            ColorBgra CurrentPixel = src[x,y];

            // Split the pixel's color into pieces
            HsvColor hsv = HsvColor.FromColor(CurrentPixel.ToColor());
            int H = hsv.Hue;         // 0-360
            int S = hsv.Saturation;  // 0-100
            int V = hsv.Value;       // 0-100
            byte A = CurrentPixel.A; // 0-255

            // TODO:  Modify H, S, V, and A according to some formula here
            V = Math.Max(Math.Min(V+Amount1,100),0);

            // Put the pieces back together 
            CurrentPixel = ColorBgra.FromColor(new HsvColor(H,S,V).ToColor());
            CurrentPixel.A = A;

            // Save to destination canvas to see the result
            dst[x,y] = CurrentPixel;
        }
    }
}

 

Hope this helps!

~BoltBait

  

  • Like 1
Link to comment
Share on other sites

On 12/26/2020 at 1:59 PM, Reptillian said:

Also, @ardneh doesn't seem to address on subtract part.

Okay.

 

So, based on two randomly chosen colors,
H90 S88 V49 and H0 S50 V49, to reduce
V by 17:

 

Select the area you want to darken.
Copy and paste into a New Layer.
Set new layer Properties to Color Burn.
Adjust Opacity to 90. 

 

Sadly, this is no solution.


Pixels with different starting Values
will need different Opacity settings.

 

Also, any pixel with V from 84 to 100
could never have the V raised by 17.

 

Neither could a pixel at V of 0 to 16
have its V reduced by 17.
 

Edited by ardneh
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...