Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A tool to convert colored images into grayscale called "colorfilter", based on OpenCV #39

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/colorfilter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
*.jpg
*.png
11 changes: 11 additions & 0 deletions scripts/colorfilter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required (VERSION 3.8)

project ("OI WIKI Color Filter")

find_package(OpenCV REQUIRED)
# opencv include path: /opt/opencv

include_directories(${OpenCV_INCLUDE_DIRS})
link_libraries(${OpenCV_LIBS})

add_executable (colorfilter "main.cpp")
51 changes: 51 additions & 0 deletions scripts/colorfilter/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int main(int argc, char *argv[]) {
int nx, ny;
Mat channels[3];

Mat img = imread(argv[1]);

Mat cell_small = imread("masksmall.bmp");
Mat cell_mid = imread("maskmid.bmp");
Mat cell_big = imread("maskbig.bmp");

Mat mask_small;
nx = img.size().width / cell_small.size().width + 1;
ny = img.size().height / cell_small.size().height + 1;
repeat(cell_small, ny, nx, mask_small);
mask_small = mask_small(Range(0, img.size().height), Range(0, img.size().width));


Mat mask_mid;
nx = img.size().width / cell_mid.size().width + 1;
ny = img.size().height / cell_mid.size().height + 1;
repeat(cell_mid, ny, nx, mask_mid);
mask_mid = mask_mid(Range(0, img.size().height), Range(0, img.size().width));

Mat mask_big;
nx = img.size().width / cell_big.size().width + 1;
ny = img.size().height / cell_big.size().height + 1;
repeat(cell_big, ny, nx, mask_big);
mask_big = mask_big(Range(0, img.size().height), Range(0, img.size().width));

Mat img_small = mask_small & img;
split(img_small, channels);
img_small = channels[0] + channels[1] + channels[2];

Mat img_mid = mask_mid & img;
split(img_mid, channels);
img_mid = channels[0] + channels[1] + channels[2];

Mat img_big = mask_big & img;
split(img_big, channels);
img_big = channels[0] + channels[1] + channels[2];

imwrite(string(argv[1]) + ".small.jpg", img_small);
imwrite(string(argv[1]) + ".mid.jpg", img_mid);
imwrite(string(argv[1]) + ".big.jpg", img_big);
return 0;
}
Binary file added scripts/colorfilter/maskbig.bmp
Binary file not shown.
Binary file added scripts/colorfilter/maskmid.bmp
Binary file not shown.
Binary file added scripts/colorfilter/masksmall.bmp
Binary file not shown.
Loading