Skip to content

Commit

Permalink
Make color wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
burk committed Dec 12, 2014
1 parent 38b4460 commit ffce5a6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ avg
imgdiff
methodnoise
sobel
colorwheel

# CMake
CMakeCache.txt
Expand All @@ -56,6 +57,8 @@ callgrind.out.*
*.bmp
*.pgm
*.png
*.jpg
*.gif

# VIM
*.swp
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ add_executable(avg avg.cpp)
add_executable(imgdiff imgdiff.cpp)
add_executable(methodnoise methodnoise.cpp)
add_executable(sobel sobel.cpp graph.cpp selectionrule.cpp image.cpp)
add_executable(colorwheel colorwheel.cpp)
#target_link_libraries(image-restoration ${OpenCV_LIBS})
target_link_libraries(avg ${OpenCV_LIBS})
target_link_libraries(imgdiff ${OpenCV_LIBS})
target_link_libraries(methodnoise ${OpenCV_LIBS})
target_link_libraries(sobel ${OpenCV_LIBS})
target_link_libraries(colorwheel ${OpenCV_LIBS})
56 changes: 56 additions & 0 deletions colorwheel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <unistd.h>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main(int argc, char *argv[]) {
Size size(512, 512);

Mat h = Mat::ones(size, CV_64F);
Mat s = Mat::ones(size, CV_64F);
Mat v = Mat::ones(size, CV_64F);
Mat hsv;
vector<Mat> channels;

Point center(size.height / 2, size.width / 2);
for (int i = 0; i < size.height; ++i) {
for (int j = 0; j < size.width; ++j) {
int x = j - center.x;
int y = i - center.y;

if (sqrt(x*x + y*y) > size.width / 2.0) {
h.at<double>(i, j) = 0;
s.at<double>(i, j) = 0;
v.at<double>(i, j) = size.width / sqrt(4.0);
continue;
}

h.at<double>(i, j) = fmod(atan2(y, x) * 180.0 / M_PI + 180.0, 180.0);
s.at<double>(i, j) = 255;
v.at<double>(i, j) = sqrt(y*y + x*x);
}
}

Mat ho, so, vo;
normalize(h, ho, 0, 180, NORM_MINMAX, CV_8U);
normalize(s, so, 0, 255, NORM_MINMAX, CV_8U);
normalize(v, vo, 0, 255, NORM_MINMAX, CV_8U);

channels.push_back(ho);
channels.push_back(so);
channels.push_back(vo);
merge(channels, hsv);

Mat colortensor;
cvtColor(hsv, colortensor, CV_HSV2BGR);

imwrite("wheel.png", colortensor);

return 0;
}

0 comments on commit ffce5a6

Please sign in to comment.