├── favicon.png ├── comparison.png ├── img ├── mario.jpg ├── lighthouse.jpg ├── starrynight.jpg └── woody-allen.jpg ├── screenshot.png ├── LICENSE ├── README.md └── index.html /favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victorqribeiro/pixelRestorer/HEAD/favicon.png -------------------------------------------------------------------------------- /comparison.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victorqribeiro/pixelRestorer/HEAD/comparison.png -------------------------------------------------------------------------------- /img/mario.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victorqribeiro/pixelRestorer/HEAD/img/mario.jpg -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victorqribeiro/pixelRestorer/HEAD/screenshot.png -------------------------------------------------------------------------------- /img/lighthouse.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victorqribeiro/pixelRestorer/HEAD/img/lighthouse.jpg -------------------------------------------------------------------------------- /img/starrynight.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victorqribeiro/pixelRestorer/HEAD/img/starrynight.jpg -------------------------------------------------------------------------------- /img/woody-allen.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victorqribeiro/pixelRestorer/HEAD/img/woody-allen.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Victor Ribeiro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pixelRestorer 2 | 3 | Using statistics to restore pixel art images. 4 | 5 |  6 | 7 | A live version of it is hosted [here](https://victorribeiro.com/pixelRestorer) 8 | 9 | ## How to use 10 | 11 | Select the image, the way of redrawing it ([mean, mode or median](https://www.khanacademy.org/math/statistics-probability/summarizing-quantitative-data/mean-median-basics/a/mean-median-and-mode-review)) and click Run or Hit Enter on the keyboard. 12 | 13 | The processing is animated so you can see the algorithm working (it's not slow it was programmed like that). 14 | 15 | ## About 16 | 17 | This is a project I've been idealizing from some time now. Is it possible to reconstruct a pixel art image that has been corrupted by scaling or compression, using statistics? Well, lets give it a shot. 18 | 19 | ## The Algorithm 20 | 21 | The first step is to determine the image's "pixel size". The algorithm does that by diving the image in windows and calculating the probability of that window being the pixel size. 22 | 23 | ``` 24 | window = imageSize / 2 25 | window = imageSize / 4 26 | window = imageSize / 6 27 | ... 28 | ``` 29 | 30 | The window is a square matrix. 3x3, 6x6, 8x8... 31 | 32 | It stores all the probabilities in a dictionary then returns the most likely to be the right pixel size - the greater value. 33 | 34 | The algorithm calculates the probability of the window by getting the mean - sum of pixels divided by total pixels - of the area and comparing it to the median - element on the center of the array - plus some threshold. That's a way I found to calculate the entropy of the window. A window with low entropy must mean that the pixels in there are smiliar, right?! 35 | 36 | The second step is to redraw the image pixelSize by pixelSize getting the mean, mode or median of each pixelSize. E.g.: The algorithm determined that the pixelSize is 8x8. So, it gets a 8x8 patch of the image, take the mean, the mode or the median and redraw every real pixel (1x1) with that value. So now the pixelSize - the window of 8x8 - is now filled with pixels of the same value. 37 | 38 | Here's a comparison: 39 | 40 |  41 | 42 | It got rid of most artefacts caused by scaling or compressing the original image. 43 | 44 | ## Known problems 45 | 46 | The algorithm does not work 100% of the cases nor with every possible image. For example, it doesn't work if the pixelSize is offsetted or if the image has a large area of the same color - as a background for instance. 47 | 48 | If most of the image is similar, like a image with a large solid white color as background and just a small portion of it being the pixel art, it can't figure out the right size of the pixelSize. Cause every window will have a low entropy value (since its most white, no matter what). 49 | 50 | It also blurs the images sometimes (most of the times), due to the fact that the image was scaled to some odd value (and the pixel seize its no a integer - like, it guessed the pixel size would be 6,5x6,5). 51 | 52 | Also the code is a mess and has a lot of hard coded values in it. Sorry, I'll might refactor it later. 53 | 54 | ## Disclaimer 55 | 56 | I do not own the images used in the examples, I googled them. If you are or know the authors, contact me and will give proper credit. 57 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |