Jump to content

Desaturate Plugin?


Recommended Posts

Looking for quick searches, I am not looking at any plugins that will allow me to convert a color to black and white to the following :

 

  • Lightness based on the HSL model (Can't be done with gradient map reliably. Close sometimes, but not always)
  • Luminosity (Default Black and White) (Looks close to ITU-R BT.709)
  • Value(Not sure)
  • Average of Channel (Not possible)
  • Min Channel (Not possible)
  • Max Channel (Not possible)

 

The issue with the current one is that I need Lightness based on the HSL model, and Paint.NET has yet to have a plugin like that.

 

And this raises another question.  Why is luminosity on the default black and white different than luminosity in plugins? In plugins, it's using the HSL *L.

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

I'm more interested into selecting one of those option, and then the hypothetical plugins leads me to one of those result.Tried the Black and White+, but the sliders aren't exactly what I want to be seeing. There is an application where I use pixel sort to figure out gradient mapping of a image which involves applying grayscale operation to figure out how it was mapped. Some people use luminosity to map, and other use lightness, and sometimes people use one of the channel to map.

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

Yes, C# is the Paint.NET programming language. Strictly speaking, any managed .NET language, such as C++/CLI, will work for writing plugins, but  virtually every plugin is written in C#. I vaguely recall there were some plugins written in Visual Basic. Anyone who knows C++ should have no problem writing C#.

Link to comment
Share on other sites

Getting a copy of Codelab is your easiest intro to plugin writing.

 

Here's something to get you started:

 

/* ================================================================================= */
/*                                                                                   */
/*   Intensity Map.cs                                                                */
/*   (c) 2010 Ego Eram Reputo                                                        */
/*                                                                                   */
/*   Description: Converts the selection/image into an intensity (greyscale) map     */
/*                                                                                   */
/* ================================================================================= */

// Name: Intensity Map
// Author: Ego Eram Reputo
// Submenu: Color
// URL: http://www.getpaint.net/redirect/plugins.html
// Title: Intensity Map - 2010 Ego Eram Reputo

void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    
    byte v = 0;
     
    ColorBgra CurrentPixel;
    
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x,y];

            v =  Intensity(CurrentPixel);
            
            CurrentPixel = ColorBgra.FromBgra(v,v,v,255);
            
            dst[x,y] = CurrentPixel;
        }
    }
}
// *************** Intensity Method *************** 
//
//  Returns the intensity (byte) of the source color.  Over a fully opaque image, this functions as Advanced Desaturate.
//  
//      Exceedingly bright = intensity of 255.
//      Very, very dim  = intensity of 0.
//      A partially transparent pixel should be less intense than the same pixel if it was fully opaque.
//
//      Initially...    (R + G + B)/3 * A / 255 
//
//      Exponential scaling of Alpha channel better deals with partial transparency.  
//      So an Alpha value < 255 increasingly biases the resultant intensity towards zero....,
//
//           (R + G + B)/3 * (A * A) / (255*255)  
// 
//      The RGB channels themselves have different intensities, so scaling these yields an 
//      even better result, which is slightly brighter than the previous formula....,
//
//           (scaled.R + scaled.G + scaled.B) * (A * A) / (255*255)    
//
// Lambda Expression:  Not working in codelab?
//    Func<ColorBgra, byte> Intensity = iColor => (iColor.R + iColor.G + iColor.B) * iColor.A * iColor.A / 195075;

private byte Intensity(ColorBgra iColor)
{
      byte Intensity = 0;
//      Intensity = (byte)((iColor.R + iColor.G + iColor.B) * iColor.A / 765 );     // first formula
//      Intensity = (byte)((iColor.R + iColor.G + iColor.B) * iColor.A * iColor.A / 195075 );       second formula
      Intensity = (byte)(( (iColor.R * 0.299) + (iColor.G * 0.587) + (iColor.B * 0.114)) * iColor.A * iColor.A / 65025 );
      return Intensity;  
}
// ************* Intensity Method Ends ************ 

 

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.

 Share

×
×
  • Create New...