Jump to content
How to Install Plugins ×

Selective Transparency


Recommended Posts

This plugin will take the brightness of the pixels in an image, and make them transparent based on the values from the GUI.

located in Effects > Transparency

 

It was created to take different exposure images and combine them into a sort of HDR image. It's pretty simple in concept so I'll give an example of how I use the plugin.

 

High, Mid, and Low exposure images:

ST_1.1.jpg.f076614444e39d6f930dce866d755e4b.jpg

 

On the high-exposure image, I make the bright pixels transparent so that I have detail in the dark areas. And on the low-exposure image, I make the dark pixels transparent so that I have detail in the bright areas. Then I merge those layers (just "Normal" layer blend mode) onto the mid-exposure image.

ST_2.1.jpg.c29b5caafc0c46349fda454303335d93.jpg

 

In the end, I have a photo with more dynamic range than what my basic phone camera could have gotten just on it's own.

ST_Final.1.thumb.jpg.b758c3b9830cb8603eb79a84567d108f.jpg

Download:

SelectiveTransparency.zip

 

CodeLabs Code:

Spoiler
// Name: Selective Transparency
// Submenu: Transparency
// Author: Skysworld
// Title: Selective Transparency
// Version: 1.0
// Desc: Make pixels transparent based on their brightness 
// Keywords: transparent|transparency
// URL: https://forums.getpaint.net/profile/171721-skysworld/
// Help: https://forums.getpaint.net/profile/171721-skysworld/
#region UICode
RadioButtonControl greatLess = 0; // Effect Pixels..|Greater Than|Less Than
IntSliderControl intensity = 50; // [0,100,5] Brightness
IntSliderControl thresh = 5; // [0,10] Threshold
#endregion

protected override void OnDispose(bool disposing)
{
    if (disposing)
    {
    }
    base.OnDispose(disposing);
}

void PreRender(Surface dst, Surface src)
{
}

void Render(Surface dst, Surface src, Rectangle rect)
{
    //Loop through image's pixels
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            ColorBgra SrcPixel = src[x,y];
            ColorBgra CurrentPixel;
            int newAlpha = SrcPixel.A;
            
            //===============Code Start===============
            byte mostLumous;
            int pixelBrightness;
            mostLumous = SrcPixel.R;
            if (SrcPixel.G > mostLumous) {
                mostLumous = SrcPixel.G;
            }
            if (SrcPixel.B > mostLumous) {
                mostLumous = SrcPixel.B;
            }
            pixelBrightness = ((int)(mostLumous/2.55));

            //===============Code Start===============
            if (greatLess == 0) //Greater than
            {
                if (pixelBrightness > intensity) {
                newAlpha = (((int)SrcPixel.A) - Math.Abs(11-thresh)*((int)(pixelBrightness) - intensity));
                    if (newAlpha < 0) {newAlpha = 0;}
                }
            } else { //Less Than
                if (pixelBrightness < intensity) {
                    newAlpha = (((int)SrcPixel.A) - Math.Abs(11-thresh)*(intensity - ((int)(pixelBrightness))));
                    if (newAlpha < 0) {newAlpha = 0;}
                }
            }
            //===============Code End===============
            CurrentPixel = ColorBgra.FromBgra(SrcPixel.B, SrcPixel.G, SrcPixel.R, (byte)newAlpha);
            dst[x,y] = CurrentPixel;
        }
    }
}

 

 

Edited by Skysworld
  • Like 7
  • Upvote 1
Link to comment
Share on other sites

18 hours ago, Skysworld said:
protected override void OnDispose(bool disposing)
{
    if (disposing)
    {
    }
    base.OnDispose(disposing);
}

void PreRender(Surface dst, Surface src)
{
}

 

These two methods do literally nothing. You can just delete them from your source code.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

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...