Skip to content

Commit

Permalink
Add push color control
Browse files Browse the repository at this point in the history
  • Loading branch information
TianZerL committed Apr 11, 2020
1 parent 8425d20 commit c8cb9dd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
6 changes: 4 additions & 2 deletions Anime4K09/include/Anime4K.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Anime4K
public:
Anime4K(
int passes = 2,
int pushColorCount = 2,
double strengthColor = 0.3,
double strengthGradient = 1.0,
double zoomFactor = 2.0,
Expand Down Expand Up @@ -56,6 +57,7 @@ class Anime4K
private:
const static int B = 0, G = 1, R = 2, A = 3;
int orgH, orgW, H, W;
double fps;
size_t totalFrameCount, frameCount;
cv::Mat orgImg, dstImg;
cv::VideoCapture video;
Expand All @@ -64,8 +66,8 @@ class Anime4K
std::condition_variable cnd;
private://arguments
unsigned int mt;
int ps;
double sc, sg, zf, fps;
int ps, pcc;
double sc, sg, zf;
bool fm, vm, pp;
uint8_t fl;
};
15 changes: 8 additions & 7 deletions Anime4K09/src/Anime4K.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Anime4K::Anime4K(
int passes,
int pushColorCount,
double strengthColor,
double strengthGradient,
double zoomFactor,
Expand All @@ -11,9 +12,9 @@ Anime4K::Anime4K(
uint8_t filters,
unsigned int maxThreads
) :
ps(passes), sc(strengthColor),
sg(strengthGradient), zf(zoomFactor),
fm(fastMode), vm(videoMode),
ps(passes), pcc(pushColorCount),
sc(strengthColor), sg(strengthGradient),
zf(zoomFactor), fm(fastMode), vm(videoMode),
pp(postProcessing), fl(filters), mt(maxThreads)
{
orgH = orgW = H = W = 0;
Expand Down Expand Up @@ -74,6 +75,7 @@ void Anime4K::showInfo()
std::cout << orgW << "x" << orgH << " to " << W << "x" << H << std::endl;
std::cout << "----------------------------------------------" << std::endl;
std::cout << "Passes: " << ps << std::endl
<< "pushColorCount: " << pcc << std::endl
<< "Zoom Factor: " << zf << std::endl
<< "Video Mode: " << std::boolalpha << vm << std::endl
<< "Fast Mode: " << std::boolalpha << fm << std::endl
Expand Down Expand Up @@ -125,7 +127,7 @@ void Anime4K::process()
for (int i = 0; i < ps; i++)
{
getGray(dstImg);
if (sc)
if (sc && (pcc-- > 0))
pushColor(dstImg);
getGradient(dstImg);
pushGradient(dstImg);
Expand All @@ -135,7 +137,6 @@ void Anime4K::process()
cv::cvtColor(dstImg, dstImg, cv::COLOR_BGRA2BGR);
PostProcessor(dstImg, fl).process();
}

}
else
{
Expand All @@ -152,15 +153,15 @@ void Anime4K::process()
break;
}

pool.exec<std::function<void()>>([orgFrame = orgFrame.clone(), dstFrame = dstFrame.clone(), this, curFrame]()mutable
pool.exec<std::function<void()>>([orgFrame = orgFrame.clone(), dstFrame = dstFrame.clone(), this, curFrame, pcc = this->pcc]()mutable
{
cv::resize(orgFrame, dstFrame, cv::Size(0, 0), zf, zf, cv::INTER_CUBIC);
if (dstFrame.channels() == 3)
cv::cvtColor(dstFrame, dstFrame, cv::COLOR_BGR2BGRA);
for (int i = 0; i < ps; i++)
{
getGray(dstFrame);
if (sc)
if (sc && (pcc-- > 0))
pushColor(dstFrame);
getGradient(dstFrame);
pushGradient(dstFrame);
Expand Down
5 changes: 4 additions & 1 deletion Anime4K09/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int main(int argc, char* argv[])
opt.add<std::string>("input", 'i', "File for loading", false, "./pic/p1.png");
opt.add<std::string>("output", 'o', "File for outputting", false, "output.png");
opt.add<int>("passes", 'p', "Passes for processing", false, 2);
opt.add<int>("pushColorCount", 'n', "Limit the number of color pushes", false, 2);
opt.add<double>("strengthColor", 'c', "Strength for pushing color,range 0 to 1,higher for thinner", false, 0.3, cmdline::range(0.0, 1.0));
opt.add<double>("strengthGradient", 'g', "Strength for pushing gradient,range 0 to 1,higher for sharper", false, 1.0, cmdline::range(0.0, 1.0));
opt.add<double>("zoomFactor", 'z', "zoom factor for resizing", false, 2.0);
Expand All @@ -40,7 +41,7 @@ int main(int argc, char* argv[])
opt.add<unsigned int>("filters", 'e',
"Enhancement filter, only working when postProcessing is true,there are 5 options by binary:\
Median blur=000001, Mean blur=000010, Gaussian blur weak=000100, Gaussian blur=001000, Bilateral filter=010000, Bilateral filter faster=100000, \
you can freely combine them, eg: Gaussian blur weak + Bilateral filter = 000100 & 010000 = 010100 = 20(D), \
you can freely combine them, eg: Gaussian blur weak + Bilateral filter = 000100 | 010000 = 010100 = 20(D), \
so you can put 20 to enable Gaussian blur weak and Bilateral filter, which also is what I recommend for image that < 1080P, \
24 for image that >= 1080P, and for performance I recommend to use 36 for video that < 1080P, 40 for video that >=1080P",
false, 20, cmdline::range(1, 63));
Expand All @@ -50,6 +51,7 @@ false, 20, cmdline::range(1, 63));
std::string input = opt.get<std::string>("input");
std::string output = opt.get<std::string>("output");
int passes = opt.get<int>("passes");
int pushColorCount = opt.get<int>("pushColorCount");
double strengthColor = opt.get<double>("strengthColor");
double strengthGradient = opt.get<double>("strengthGradient");
double zoomFactor = opt.get<double>("zoomFactor");
Expand All @@ -63,6 +65,7 @@ false, 20, cmdline::range(1, 63));
//Anime4K
Anime4K anime4k(
passes,
pushColorCount,
strengthColor,
strengthGradient,
zoomFactor,
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This is an implementation of Anime4K in C++. It based on the [bloc97's Anime4K](https://github.com/bloc97/Anime4K) algorithm version 0.9 and some optimizations have been made, it can process both image and video.
This project is for learning and the exploration task of algorithm course in SWJTU.

***NOTICE: Thanks for the high performance of pointer, the C++ version will be very fast. It is about 6.5 times faster than [Go version](https://github.com/TianZerL/Anime4KGo), and 650 times faster than [Python version](https://github.com/TianZerL/Anime4KPython), but please understand, this is executed in CPU, for video preprocessing, it will take a while. Therefore, if your graphic card is good enough, I recommend you to use the real-time process version by [bloc97](https://github.com/bloc97/Anime4K), if your CPU is powerful or you want higher quality, just try this.***
***NOTICE: Thanks for the high performance of pointer and parallel, the C++ version will be very fast. It is about 12 times faster than [Go version](https://github.com/TianZerL/Anime4KGo), and 1300 times faster than [Python version](https://github.com/TianZerL/Anime4KPython), just try this for higher quality and speed.***

# pyanime4k
[pyanime4k](https://github.com/TianZerL/pyanime4k) is a simply package to use anime4k in python, easy, fast and powerful, which support both image and video processing, based on Anime4KCPP.
Expand All @@ -24,6 +24,7 @@ This project uses [cmake](https://cmake.org) to build.
-i, --input File for loading (string [=./pic/p1.png])
-o, --output File for outputting (string [=output.png])
-p, --passes Passes for processing (int [=2])
-n, --pushColorCount Limit the number of color pushes (int [=2])
-c, --strengthColor Strength for pushing color,range 0 to 1,higher for thinner (double [=0.3])
-g, --strengthGradient Strength for pushing gradient,range 0 to 1,higher for sharper (double [=1])
-z, --zoomFactor zoom factor for resizing (double [=2])
Expand All @@ -32,7 +33,7 @@ This project uses [cmake](https://cmake.org) to build.
-v, --videoMode Video process
-s, --preview Preview image
-a, --postProcessing Enable post processing
-e, --filters Enhancement filter, only working when postProcessing is true,there are 5 options by binary:Median blur=000001, Mean blur=000010, Gaussian blur weak=000100, Gaussian blur=001000, Bilateral filter=010000, Bilateral filter faster=100000, you can freely combine them, eg: Gaussian blur weak + Bilateral filter = 000100 & 010000 = 010100 = 20(D), so you can put 20 to enable Gaussian blur weak and Bilateral filter, which also is what I recommend for image that < 1080P, 24 for image that >= 1080P, and for performance I recommend to use 36 for video that < 1080P, 40 for video that >=1080P (unsigned int [=20])
-e, --filters Enhancement filter, only working when postProcessing is true,there are 5 options by binary:Median blur=000001, Mean blur=000010, Gaussian blur weak=000100, Gaussian blur=001000, Bilateral filter=010000, Bilateral filter faster=100000, you can freely combine them, eg: Gaussian blur weak + Bilateral filter = 000100 | 010000 = 010100 = 20(D), so you can put 20 to enable Gaussian blur weak and Bilateral filter, which also is what I recommend for image that < 1080P, 24 for image that >= 1080P, and for performance I recommend to use 36 for video that < 1080P, 40 for video that >=1080P (unsigned int [=20])
-?, --help print this message

# Filters
Expand All @@ -46,7 +47,7 @@ Enable filters can make the result like better, now Anime4kCPP support 5 filters
- Bilateral filter faster [100000]

You can freely combine them by their binary.
eg: Gaussian blur weak + Bilateral filter = 000100 & 010000 = 010100(B)= 20(D)
eg: Gaussian blur weak + Bilateral filter = 000100 | 010000 = 010100(B)= 20(D)

Easily use ```-a``` to enable filters function, and then use ```-e``` to custom your own combination, normally, if you don't specify the ```-e``` manually it will be 20. You can use command like this to enable Gaussian blur and Bilateral filter:

Expand Down

0 comments on commit c8cb9dd

Please sign in to comment.