Jump to content

Masking plugin


Recommended Posts

I think the title is painful enough for any coder. Chroma key Masking. I don't need it, as I already have Recomposite. But just imagine how many people would download this plugin*! It would be the only freeware Chroma key masking tool ever made!

An example of masking (I did myself in 2 minutes):

Before

SEN950636.jpg

After

glass.png

It could be the biggest thing since Paint.NET!

*also note that this plugin will only work on Paint.NET

"The greatest thing about the Internet is that you can write anything you want and give it a false source." ~Ezra Pound

twtr | dA | tmblr | yt | fb

Link to comment
Share on other sites

usedHONDA:

Actually, for those who must do this, The GIMP does have a Color to Alpha function that does this: Non PDN image warning!

wineglass.png

And Barkbark, how did you accomplish your results?

I am not a mechanism, I am part of the resistance;

I am an organism, an animal, a creature, I am a beast.

~ Becoming the Archetype

Link to comment
Share on other sites

A competition it is!

This isn't great, but I did this:

meh.png

Parts of this:

theultimatevistabar.png

I did this a week ago:

j2k.png

This is one of the exploded planets:

coolness.png

EDIT: Just when you think you have all the plugins....

"The greatest thing about the Internet is that you can write anything you want and give it a false source." ~Ezra Pound

twtr | dA | tmblr | yt | fb

Link to comment
Share on other sites

I was able to get this with the Alpha Mask Import plugin. I inverted the wine glass, used Brightness / Contrast ... to cover most of what was there, and lo and behold:

wineglasspdn.png

It's still not perfect, and what I love about color to Alpha is that, if the pixels are a light red, the white is removed and the red hue remains and blends into the layers behind it.

I agree that this is a feature I'd love, and I know I tried to explain it to Rick before. If anyone could replicate a plugin for PDN that does this, I would have to bow in humble adoration. :D

I am not a mechanism, I am part of the resistance;

I am an organism, an animal, a creature, I am a beast.

~ Becoming the Archetype

Link to comment
Share on other sites

If anyone could replicate a plugin for PDN that does this, I would have to bow in humble adoration.

Guess what:

pdn_c2a_teaser.png

Shipping expected within the next decade. Yeah I said decade.

No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio

Link to comment
Share on other sites

... I agree that this is a feature I'd love, and I know I tried to explain it to Rick before.

And I think I've articulated several times that what I'm really driving towards are the more general concept and implementation of layer masks :) Then once you have that it becomes trivial to do about 500 new scenarios.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

1. Get HSV value of a pixel.

2. Given a set Hue, Hue tolerance, and Saturation tolerance.

3. Set A=255 if pixel.H > H+hT+1 OR pixel.H < H-hT-1

4. Set A=0 if pixel.H < H+hT-1 OR pixel.H > H-hT+1

5. If else, set A = (Math.abs(pixel.H-H+hT)*128)

^My concept

~~

Link to comment
Share on other sites

And I think I've articulated several times that what I'm really driving towards are the more general concept and implementation of layer masks :)

I apologize. I wasn't trying to insult your ability to understand, I was insulting my ability to explain exactly what it does. :wink:

I know layer masks are important, and I'm really looking forward to them, but layer masks really don't do the same thing, not without some editing and trickery.

I am not a mechanism, I am part of the resistance;

I am an organism, an animal, a creature, I am a beast.

~ Becoming the Archetype

Link to comment
Share on other sites

Hmm.... A prototype for codelab, right here (Really, dirty and hacky)

int Amount1=120; //Base Hue green=120, blue=240, reds aren't supported very well
int Amount2=50; //Hue Tolerance
int Amount3=16; //Value tolerance

const double HSV_UNDEFINED = -999.0;

void Render(Surface dst, Surface src, Rectangle rect)
{
   float BaseHue = Amount1;
   float HueTol = Amount2;
   float VTol = (float)Amount3;
   double H = 0, S = 0, V = 0;
   VTol /= 100f;
   for(int y = rect.Top; y < rect.Bottom; y++)
   {

       for (int x = rect.Left; x < rect.Right; x++)
       {
           ColorBgra col = src[x, y];

           EvanRGBtoHSV(col.R, col.G, col.B, ref H, ref S, ref V);
           if (V > VTol) {
               if (H > (BaseHue-HueTol+3)&&H > (BaseHue+HueTol-3)||H < (BaseHue-HueTol+3)&&H < (BaseHue-HueTol-3)) col.A=255;
               else col.A = 0;
               }
           dst[x, y] = col;
           }

       }

   }

public void EvanRGBtoHSV(int R, int G, int B, ref double outH, ref double outS, ref double outV)
{
// R, G, and B must range from 0 to 255
// Ouput value ranges:
// outH - 0.0 to 360.0
// outS - 0.0 to 1.0
// outV - 0.0 to 1.0

double dR = (double)R/255.0;
double dG = (double)G/255.0;
double dB = (double)B/255.0;
double dmaxRGB = EvanMax3(dR, dG, dB);
double dminRGB = EvanMin3(dR, dG, dB);
double delta = dmaxRGB - dminRGB;

// Set value
outV = dmaxRGB;

// Handle special case
if (dmaxRGB == 0)
{
outH = HSV_UNDEFINED;
outS = 0.0;
return;
}

outS = delta/dmaxRGB;
if (dmaxRGB == dminRGB)
{
outH = HSV_UNDEFINED;
return;
}

// Finally, compute hue
if (dR == dmaxRGB)
{
outH = (dG-dB)/delta*60.0;
}
else if (dG == dmaxRGB)
{
outH = (2.0+(dB-dR)/delta)*60.0;
}
else //if (dB == dmaxRGB)
{
outH = (4.0+(dR-dG)/delta)*60.0;
}

if (outH < 0)
{
outH += 360.0;
}
}

public double EvanMax3(double x, double y, double z)
{
return (x>y)?((x>z)?x:z)(y>z)?y:z);
}
public double EvanMin3(double x, double y, double z)
{
return (x(y}

Last 3 functions were made by EvanOlds, best to attribute him.

Okay, here's an example for the wine glass.

I took the white background to blue because white is the most difficult color to mask out.

blueglass.png

Now, Amount1 = 240, for blue. Amount2 = 40, for good hue range. Amount3 = 56, to catch some of the edges.

After:

transglass.png

The blue is still visible, but it's a prototype. ;)

~~

Link to comment
Share on other sites

Once more teasing:

SEN950636_imclose.png

startingimage_imclose.png

Still some rounding errors *bangs his head against the wall*.

I restarted from (gimp) scratch this morning ECT, the main work begin now ...

No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio

Link to comment
Share on other sites

Here is the current code, if some coding fairies want to look at it.

I don't know if I can go further.

/*
* /!\ Warning, this is GPL code!
* Color2Alpha Paint.NET plugin by Bibinou based on :
* Color To Alpha plug-in v1.0 by Seth Burgess & others, 1999/05/14
* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

void Render(Surface dst, Surface src, Rectangle rect)
{
PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);
ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;

ColorBgra CurrentPixel = new ColorBgra();
double red, key_red, green, key_green, blue, key_blue, alpha, maxalpha; 
int rnew, gnew, bnew;

for(int y = rect.Top; y < rect.Bottom; y++)
{
	for (int x = rect.Left; x < rect.Right; x++)
	{
		if (selectionRegion.IsVisible(x, y))
		{

			CurrentPixel = src[x,y];

			red = CurrentPixel.R ;
			green = CurrentPixel.G ;
			blue = CurrentPixel.B ;

			key_red = PrimaryColor.R ;
			key_green = PrimaryColor.G ;
			key_blue = PrimaryColor.B ;

			/* Store red alpha component */
			if (red   >= key_red  )
			alpha = (key_red   == 255 ? 0 : (red - key_red ) / (255 - key_red)  );
			else
			alpha = (key_red   == 0 ? red  / 255 : 1.0 - red / key_red );
			maxalpha = alpha;

			/* Store green alpha component, if greater */
			if (green >= key_green)
			alpha = (key_green == 255 ? 0 : (green - key_green) / (255 - key_green));
			else
			alpha = (key_green == 0 ? green/ 255 : 1.0 - green / key_green );
			if (alpha > maxalpha) maxalpha = alpha;

			/* Store blue alpha component, if greater */
			if (blue  >= key_blue )
			alpha = (key_blue  == 255 ? 0 : (blue  - key_blue ) / (255 - key_blue ));
			else
			alpha = (key_blue  == 0 ?  blue / 255 : 1.0 - blue / key_blue  );
			if (alpha > maxalpha) maxalpha = alpha;

			/* Threshold the alpha */ 
			//alpha = (maxalpha * 255) / pvals.threshold ;

			/* Using int to Math.Round the values */
			if (alpha > 1) alpha = 1 ;
			else if (alpha < 0) alpha = 0 ;

			if (alpha > 0) {
			rnew = (int) ( Math.Round( (red   - key_red  ) / alpha + key_red   ) ) ;
			gnew = (int) ( Math.Round( (green - key_green) / alpha + key_green ) ) ;
			bnew = (int) ( Math.Round( (blue  - key_blue ) / alpha + key_blue  ) ) ;
			}
			else {
			rnew = (int) red;
			gnew = (int) green;
			bnew = (int) blue;
			};

			if ( rnew <=255 && gnew <=255 && bnew <=255 && rnew >=0 && gnew >=0 && bnew >= 0) 
			{
			CurrentPixel.R = (byte)rnew ;
			CurrentPixel.G = (byte)gnew ;
			CurrentPixel.B = (byte)bnew ;
			CurrentPixel.A = (byte)(alpha * 255) ;

			dst[x,y] = CurrentPixel;

			}

			else
			{
				dst[x,y] = src[x,y];
			}
		}
	}
}
}
/* EOF */

No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio

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