uwe81 Posted July 11, 2015 Share Posted July 11, 2015 What am I looking for: I am looking for a plugin that takes an image and reduces the colors to a very small number (e.g. <10). Additionally, large areas should have the same color (i am not interested in single pixel having a different color than the pixels around. Where do I need this: My wife bought an embroidery machine. On the internet we can look for cliparts as embroidery pattern (private usage only). Usually we find an image that looks good. If this image only consists of, lets say, 8 images, everything is fine. We import it into the stitching program, tell the program to stitch the red parts of the image in some way, the green parts in some other way and so on. However, the program relies on the pixel to have EXACTLY the same color. The problem arises, if the image was saved as jpeg or if some antialializing smoothed black borders or something similar. What we did so far: Until now, I worked with gimp, used the function "Threshold" to make a black/white image essentially only containing the black borders and flood-filling everything again. What might be special in my case: I am not interested in single pixels. If, by antialializing, a pixel an a black border of a red area is somewhere between black and red i do not care how the plugin colors it, as long as it is either black or red. However, I do not want small areas of pixels having a different color than its neighbourhood. Quote Link to comment Share on other sites More sharing options...
BoltBait Posted July 11, 2015 Share Posted July 11, 2015 Paint.net has a built-in effect that may do the trick. Try Adjustments > Posterize. Move the sliders down to, like, 2 or 3. Or, you could try this plugin for 2 colors: Stencil.zip Once installed, it is under Effects > Color > Stencil // Name: Stencil // Submenu: Color // Author: BoltBait // Title: Stencil v1.0 // Desc: Reduce photograph down to 2 colors // Keywords: posterize|stencil // URL: http://www.BoltBait.com/pdn #region UICode int Amount1 = 10; // [-100,100] Balance ColorBgra Amount2 = ColorBgra.FromBgr(255,255,255); // Bright Color ColorBgra Amount3 = ColorBgra.FromBgr(0,0,0); // Dark Color #endregion // Setup for using pixel op private UnaryPixelOps.Desaturate desaturateOp = new UnaryPixelOps.Desaturate(); // Here is the main render loop function void Render(Surface dst, Surface src, Rectangle rect) { // Setup for calling the Brightness and Contrast Adjustment function BrightnessAndContrastAdjustment bacAdjustment = new BrightnessAndContrastAdjustment(); PropertyCollection bacProps = bacAdjustment.CreatePropertyCollection(); PropertyBasedEffectConfigToken bacParameters = new PropertyBasedEffectConfigToken(bacProps); bacParameters.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Brightness, Amount1); bacParameters.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Contrast, 100); bacAdjustment.SetRenderInfo(bacParameters, new RenderArgs(dst), new RenderArgs(src)); // Call the Brightness and Contrast Adjustment function bacAdjustment.Render(new Rectangle[1] {rect},0,1); // Now in the main render loop, the dst canvas has an adjusted version of the src canvas for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { ColorBgra CurrentPixel = dst[x,y]; CurrentPixel = desaturateOp.Apply(CurrentPixel); if (CurrentPixel.R > 128) { CurrentPixel = Amount2; } else { CurrentPixel = Amount3; } dst[x,y] = CurrentPixel; } } } For a truly complicated, but amazing, color reduction effect, try this plugin: http://forums.getpaint.net/index.php?/topic/29428-z 1 Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
Cc4FuzzyHuggles Posted July 11, 2015 Share Posted July 11, 2015 You might like these plugins: http://forums.getpaint.net/index.php?/topic/29450-two-tone-threshold-new-30th-july-2014/ http://forums.getpaint.net/index.php?/topic/29424-trs-color-reducer-and-palette-maker-2014-08-01/ Quote *~ Cc4FuzzyHuggles Gallery ~* Link to comment Share on other sites More sharing options...
MJW Posted July 13, 2015 Share Posted July 13, 2015 You might try Neil Cassidy's Color Segmentation plugin. It's along the lines of what you're trying to accomplish. Quote Link to comment Share on other sites More sharing options...
uwe81 Posted July 13, 2015 Author Share Posted July 13, 2015 Hello! Thank you for your answers! However, I am not quite happy with these plugins. All of them (including the built-in function) seem to work pixel-wise, i.e. each pixel is rounded to the next color. By this I get artefacts as shown below. To an human it is quite clear that I do not want to have any orange inside the white region on the left, however there are some orange pixels inside... Quote Link to comment Share on other sites More sharing options...
MJW Posted July 13, 2015 Share Posted July 13, 2015 The color segmentation doesn't work pixel-wise. I think what you want to do is difficult; perhaps nearly impossible do to automatically, since the program can't read your mind. If the small isolated color region is an eye in an image of a face, you'd want to keep it, tiny as it may be. Quote Link to comment Share on other sites More sharing options...
Eli Posted July 13, 2015 Share Posted July 13, 2015 Does the machine work only with jpegs? If the machine accepts vectors you may try some software that converts raster images to vectors. Vector Magic for example allows you to pick the number of colours you want to keep. You can save it in SVG format and do further edit with Inkscape. Quote Link to comment Share on other sites More sharing options...
BoltBait Posted July 14, 2015 Share Posted July 14, 2015 However, I am not quite happy with these plugins. All of them (including the built-in function) seem to work pixel-wise, i.e. each pixel is rounded to the next color. By this I get artefacts as shown below. To an human it is quite clear that I do not want to have any orange inside the white region on the left, however there are some orange pixels inside... After the using the built-in effect, try this CodeLab script to eliminate stray pixels... // Name: Stray Pixels // Submenu: Color // Author: BoltBait // Title: Eliminate Stray Pixels // URL: http://BoltBait.com/pdn #region UICode int Amount1 = 1; // [0,4] Size #endregion void Render(Surface dst, Surface src, Rectangle rect) { for (int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { ColorBgra CurrentPixel = src[x,y]; ColorBgra newPixel = src[x,y]; ColorBgra testPixel = src[x,y]; int MatchCount = 0; for (int TestY = y - 1; TestY < y + 2; TestY++) { for (int TestX = x - 1; TestX < x + 2; TestX++) { if ((TestX >= 0) && (TestX < src.Width) && (TestY >= 0) && (TestY < src.Height)) { if ((TestX != x) || (TestY != y)) { testPixel = src[TestX,TestY]; if (CurrentPixel != testPixel) { newPixel = testPixel; } else { MatchCount = MatchCount+1; } } } } } if (MatchCount < Amount1) { CurrentPixel = newPixel; } dst[x,y] = CurrentPixel; } } }It is a bit rough as I wrote it in 5 minutes and haven't really tested it properly. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
Red ochre Posted July 14, 2015 Share Posted July 14, 2015 slightly off topic: Thanks BoltBait - may have to play with that code! There is already a plugin with a similar name for removing stray pixels on a transparent background.http://forums.getpaint.net/index.php?showtopic=26533 if you're not set on that name! I think any effect will need some manual 'tampering' to select what is relevant and what is noise? Quote Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings Link to comment Share on other sites More sharing options...
BoltBait Posted July 14, 2015 Share Posted July 14, 2015 I'm not stuck on that name at all. Like I said, I just wrote this in 5 minutes as a "proof of concept" just to see if I could solve the problem. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
uwe81 Posted July 14, 2015 Author Share Posted July 14, 2015 Thank you for the replies. I did not manage to test further hints, but (when I have time) I will try to write my own plugin. There are some Ideas that might heuristically solve the problem * Increase each selection by, e.g. 1 pixel before coloring * Removing stray pixel (each area of connected pixel with less than N pixel), color them by their neighbour color Although i never wrote something related to image processing I am quite experienced in C# and coding of GUIs and mathematical algrorithms. It might be worth a try... Quote Link to comment Share on other sites More sharing options...
BoltBait Posted July 14, 2015 Share Posted July 14, 2015 * Removing stray pixel (each area of connected pixel with less than N pixel), color them by their neighbour color That's what the script I posted above does. If you want to code your own plugin, here are some tutorials to get you started: http://boltbait.com/pdn/CodeLab/help/ Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.