Lanceo90 Posted January 3, 2017 Share Posted January 3, 2017 Greetings everyone, That question might not make sense at first glance so here's the more elaborate question: I have a map file made from a tile set that I want to simplify the tiles down to just a single color. There's a lot of them, and it's a big image. I started by just copy pasting but it's going to take way too long. So I was curious if Paint.net has a built in method to replace sets of pixels with another, or if there is a plugin than can do it. Here's a visual representation of what I mean using a small piece of the map: Quote Link to comment Share on other sites More sharing options...
MJW Posted January 3, 2017 Share Posted January 3, 2017 I know of no way to do this, and doubt there currently is one in PDN. I think it would be difficult to write a plugin. It would have to use a 2D equivalent of string matching. Depending on the use, it might have to find near matches, since sampling can modify a pattern when it's resized or translated. I found some reference to 2D pattern matching, such as Fast Two Dimensional Pattern Matching. Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted January 4, 2017 Share Posted January 4, 2017 I'm currently working on a tiling plugin. That might be a solution here - unfortunately the release date is some way off. 1 Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
NinthDesertDude Posted January 4, 2017 Share Posted January 4, 2017 (edited) I'm working on it. I should have a solution for you in a few days or less. Edit: Well, that was faster than expected. I've attached the .dll file. You'll need to drop it in the Effects folder under Paint.net. (An easy way to get there is to right-click paint.net, click "open file location" and do that again on the shortcut. You should see the Effects folder at the top, then.) It was fun PixSetRepl.zip ---------------------------- Instructions: Select the tile you want to change. Click the button to store it as the "image to be replaced". Select (or draw) the tile you want to replace it with. Store that as the second image. Go to it again and click "replace". You can also use "reset" to use it on multiple tiles. It might be slow on a large image. Edited January 5, 2017 by AnthonyScoffler 3 Quote Link to comment Share on other sites More sharing options...
Lanceo90 Posted January 6, 2017 Author Share Posted January 6, 2017 On 1/4/2017 at 4:07 PM, AnthonyScoffler said: I'm working on it. I should have a solution for you in a few days or less. Edit: Well, that was faster than expected. I've attached the .dll file. You'll need to drop it in the Effects folder under Paint.net. (An easy way to get there is to right-click paint.net, click "open file location" and do that again on the shortcut. You should see the Effects folder at the top, then.) It was fun PixSetRepl.zip ---------------------------- Instructions: Select the tile you want to change. Click the button to store it as the "image to be replaced". Select (or draw) the tile you want to replace it with. Store that as the second image. Go to it again and click "replace". You can also use "reset" to use it on multiple tiles. It might be slow on a large image. Wow, thanks! That worked Quote Link to comment Share on other sites More sharing options...
NinthDesertDude Posted January 6, 2017 Share Posted January 6, 2017 I'm glad it was useful. I took up the work to do that because I had some free time and, after thinking about it, it's sort of a basic utility. I hope the interface isn't too laborious -- I know it's not pretty. Quote Link to comment Share on other sites More sharing options...
NinthDesertDude Posted January 6, 2017 Share Posted January 6, 2017 @MJW Here's the main part of the code. //Iterates through each pixel. for (int y = 0; y <= src.Height - token.BmpToReplace.Height; y++) { for (int x = 0; x <= src.Width - token.BmpToReplace.Width; x++) { //Skips all pixels that have been replaced. if (replacedPixels.Count > 0 && replacedPixels[0].X == x && replacedPixels[0].Y == y) { replacedPixels.RemoveAt(0); continue; } //Checks if the first pixel matches. if (ColorBgra.FromColor(token.BmpToReplace.GetPixel(0, 0)).Equals(src[x, y])) { bool totalMatch = true; //Checks if every pixel matches. for (int yy = 0; yy < token.BmpToReplace.Height; yy++) { for (int xx = 0; xx < token.BmpToReplace.Width; xx++) { if (!ColorBgra.FromColor(token.BmpToReplace.GetPixel(xx, yy)).Equals(src[x + xx, y + yy])) { totalMatch = false; break; } } if (!totalMatch) { break; } } //Replaces the matching pixels. They will be skipped. if (totalMatch) { for (int yy = 0; yy < token.BmpReplacing.Height; yy++) { for (int xx = 0; xx < token.BmpReplacing.Width; xx++) { dst[x + xx, y + yy] = ColorBgra.FromColor(token.BmpReplacing.GetPixel(xx, yy)); //All pixels except the first should be skipped. //The first has been checked already. if (xx != 0 && yy != 0) { replacedPixels.Add(new Point(x + xx, y + yy)); } } } replacedPixels.OrderBy(p => p.X).ThenBy(p => p.Y); } } } } 1 Quote Link to comment Share on other sites More sharing options...
Eli Posted January 6, 2017 Share Posted January 6, 2017 Thanks for this tool @AnthonyScoffler, I thought I would test it by replacing some characters I typed (the characters that followed the word THANKYOU!) with the word BRAVO! To my surprise the effect found only two instances of the characters I wanted to replace. Upon closer inspection I found that the characters that were not replaced were not exactly identical everywhere. Could a tolerance option be added to the effect? Quote Link to comment Share on other sites More sharing options...
NinthDesertDude Posted January 6, 2017 Share Posted January 6, 2017 (edited) 5 hours ago, Eli said: Could a tolerance option be added to the effect? I've added it in now. I'm still working feverishly on Brush Factory, but eventually I will come back to it later and add things like a preview, which is why I didn't have tolerance the first time around. Pixel Set Replacer P.S: I was able to replace those letters using a tolerance of 220. Edited January 6, 2017 by AnthonyScoffler Source code included in download 3 Quote Link to comment Share on other sites More sharing options...
Eli Posted January 6, 2017 Share Posted January 6, 2017 @AnthonyScoffler, Thankyou! and Bravo! . It works : Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted January 22, 2017 Share Posted January 22, 2017 I just released my new Tileworld plugin: http://forums.getpaint.net/index.php?/topic/110911-tileworld/ With it you can replace tiles as our original poster requested. Demo.... It took a little jigging to get the 16x16 tile size matched to the map. After that was accomplished it was simplicity itself to click on each of the tiles to replace it. Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
Woodsy Posted January 22, 2017 Share Posted January 22, 2017 Pretty cool EER! Can't wait to try it out. Quote My PDN Gallery 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.