Skip to content

Commit

Permalink
1.0: init
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Jul 15, 2023
0 parents commit 261ff8c
Show file tree
Hide file tree
Showing 40 changed files with 1,509 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
opencv-pixartscale*


21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Anton Myronyuk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PROJECT = opencv-pixartscale
CXX = g++
OCV = opencv4
CXXFLAGS = -Wall `pkg-config --cflags $(OCV)`
LDFLAGS = `pkg-config --libs $(OCV)` -s
OBJS = src/buildingsimilaritygraph.o src/cells.o src/cellsreconstruct.o src/combine.o src/curvessearching.o src/depixelizing.o src/heuristics.o src/visualization.o src/main.o

all: $(PROJECT)

$(PROJECT): $(OBJS)
$(CXX) $^ $(LDFLAGS) -o $@

%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

clean:
$(RM) $(OBJS) $(PROJECT)
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# opencv-pixartscale

Scaling up images in low resolution (pixel art only).
Uses [OpenCV](https://opencv.org/).

## Build

Type:
```shell
make
```

## Usage

```shell
opencv-pixartscale image_in image_out scale
```

## Example

Input (x20):

![input](examples/input-x20-nn.png)

Output (x20 and reconstructed):

![output](examples/output-x20-pixartscale.png)
Binary file added examples/00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/333.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/input-x20-nn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/mario.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/output-x20-pixartscale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions src/buildingsimilaritygraph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "depixelizing.h"
void Depixelizing::buildSimilarityGraph()
{
cv::Mat imgYUV(m_image.size(), CV_8UC3);
cv::cvtColor(m_image, imgYUV, cv::COLOR_BGR2YUV);
m_connections.resize(m_width * m_height);
//building
for (int i = 0; i < m_height; ++i)
{
for (int j = 0; j < m_width; ++j)
{
cv::Vec3b& currentPixel = imgYUV.at<cv::Vec3b>(i, j);
//TOP
if (i > 0)
{
cv::Vec3b& neighbourPixel = imgYUV.at<cv::Vec3b>(i - 1, j);
if (abs(currentPixel[0] - neighbourPixel[0]) < 48 && abs(currentPixel[1] - neighbourPixel[1]) < 7 && abs(currentPixel[2] - neighbourPixel[2]) < 6)
{
m_connections[i * m_width + j] |= NEIGHBOUR_TOP;
}
}
//TOP_RIGHT
if (j < m_width - 1 && i > 0)
{
cv::Vec3b& neighbourPixel = imgYUV.at<cv::Vec3b>(i - 1, j + 1);
if (abs(currentPixel[0] - neighbourPixel[0]) < 48 && abs(currentPixel[1] - neighbourPixel[1]) < 7 && abs(currentPixel[2] - neighbourPixel[2]) < 6)
{
m_connections[i * m_width + j] |= NEIGHBOUR_TOP_RIGHT;
}
}
//RIGHT
if (j < m_width - 1)
{
cv::Vec3b& neighbourPixel = imgYUV.at<cv::Vec3b>(i, j + 1);
if (abs(currentPixel[0] - neighbourPixel[0]) < 48 && abs(currentPixel[1] - neighbourPixel[1]) < 7 && abs(currentPixel[2] - neighbourPixel[2]) < 6)
{
m_connections[i * m_width + j] |= NEIGHBOUR_RIGHT;
}
}
//BOTTOM_RIGHT
if (j < m_width - 1 && i < m_height - 1)
{
cv::Vec3b& neighbourPixel = imgYUV.at<cv::Vec3b>(i + 1, j + 1);
if (abs(currentPixel[0] - neighbourPixel[0]) < 48 && abs(currentPixel[1] - neighbourPixel[1]) < 7 && abs(currentPixel[2] - neighbourPixel[2]) < 6)
{
m_connections[i * m_width + j] |= NEIGHBOUR_BOTTOM_RIGHT;
}
}
//BOTTOM
if (i < m_height - 1)
{
cv::Vec3b& neighbourPixel = imgYUV.at<cv::Vec3b>(i + 1, j);
if (abs(currentPixel[0] - neighbourPixel[0]) < 48 && abs(currentPixel[1] - neighbourPixel[1]) < 7 && abs(currentPixel[2] - neighbourPixel[2]) < 6)
{
m_connections[i * m_width + j] |= NEIGHBOUR_BOTTOM;
}
}
//BOTTOM_LEFT
if (j > 0 && i < m_height - 1)
{
cv::Vec3b& neighbourPixel = imgYUV.at<cv::Vec3b>(i + 1, j - 1);
if (abs(currentPixel[0] - neighbourPixel[0]) < 48 && abs(currentPixel[1] - neighbourPixel[1]) < 7 && abs(currentPixel[2] - neighbourPixel[2]) < 6)
{
m_connections[i * m_width + j] |= NEIGHBOUR_BOTTOM_LEFT;
}
}
//LEFT
if (j > 0)
{
cv::Vec3b& neighbourPixel = imgYUV.at<cv::Vec3b>(i, j - 1);
if (abs(currentPixel[0] - neighbourPixel[0]) < 48 && abs(currentPixel[1] - neighbourPixel[1]) < 7 && abs(currentPixel[2] - neighbourPixel[2]) < 6)
{
m_connections[i * m_width + j] |= NEIGHBOUR_LEFT;
}
}
//TOP_LEFT
if (j > 0 && i > 0)
{
cv::Vec3b& neighbourPixel = imgYUV.at<cv::Vec3b>(i - 1, j - 1);
if (abs(currentPixel[0] - neighbourPixel[0]) < 48 && abs(currentPixel[1] - neighbourPixel[1]) < 7 && abs(currentPixel[2] - neighbourPixel[2]) < 6)
{
m_connections[i * m_width + j] |= NEIGHBOUR_TOP_LEFT;
}
}
}
}
}
void Depixelizing::deleteFullyConnectedBlocks()
{
for (int i = 0; i < m_height - 1; ++i)
{
for (int j = 0; j < m_width - 1; ++j)
{
if ((m_connections[i * m_width + j] & NEIGHBOUR_RIGHT) &&
(m_connections[i * m_width + j] & NEIGHBOUR_BOTTOM) &&
(m_connections[(i + 1) * m_width + j] & NEIGHBOUR_RIGHT) &&
(m_connections[i * m_width + (j + 1)] & NEIGHBOUR_BOTTOM))
{
m_connections[i * m_width + j] &= ~NEIGHBOUR_BOTTOM_RIGHT;
m_connections[(i + 1) * m_width + (j + 1)] &= ~NEIGHBOUR_TOP_LEFT;
m_connections[(i + 1) * m_width + j] &= ~NEIGHBOUR_TOP_RIGHT;
m_connections[i * m_width + (j + 1)] &= ~NEIGHBOUR_BOTTOM_LEFT;
}
}
}
}
Loading

0 comments on commit 261ff8c

Please sign in to comment.