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

Update answer_26.cpp #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Question_01_10/answers_cpp/answer_6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

// Dedcrease color
cv::Mat decrease_color(cv::Mat img){
int height = img.cols;
int width = img.rows;
int width = img.cols;
int height = img.rows;
int channel = img.channels();

cv::Mat out = cv::Mat::zeros(height, width, CV_8UC3);
Expand Down
31 changes: 18 additions & 13 deletions Question_11_20/answers_cpp/answer_11.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@ cv::Mat mean_filter(cv::Mat img, int kernel_size){
for (int y = 0; y < height; y++){
for (int x = 0; x < width; x++){
for (int c = 0; c < channel; c++){
v = 0;

// get pixel sum
for (int dy = -pad; dy < pad + 1; dy++){
for (int dx = -pad; dx < pad + 1; dx++){
if (((y + dy) >= 0) && ((x + dx) >= 0)){
v += (int)img.at<cv::Vec3b>(y + dy, x + dx)[c];
}
}
}
v = 0;
count = 0;

// get pixel sum
for (int dy = -pad; dy < pad + 1; dy++){
for (int dx = -pad; dx < pad + 1; dx++){
if (((y + dy) >= 0) && ((x + dx) >= 0)
&& ((y + dy) < height) && ((x + dx) < width)){
v += (int)img.at<cv::Vec3b>(y + dy, x + dx)[c];
count++;
}
}
}

// assign mean value
v /= (kernel_size * kernel_size);
out.at<cv::Vec3b>(y, x)[c] = (uchar)v;
// assign mean value
if (count > 0) {
v /= count;
out.at<cv::Vec3b>(y, x)[c] = (uchar)v;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Question_21_30/answers_cpp/answer_23.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ cv::Mat histogram_equalization(cv::Mat img){

// histogram equalization hyper-parameters
double Zmax = 255;
double hist[255];
double hist[256];
double S = height * width * channel;
int val;
double hist_sum = 0;


// histogram initialization
for (int i = 0; i < 255; i++){
for (int i = 0; i < 256; i++){
hist[i] = 0;
}

Expand All @@ -46,7 +46,7 @@ cv::Mat histogram_equalization(cv::Mat img){

// get histogram sum <= current pixel value
hist_sum = 0;
for (int l = 0; l < val; l++){
for (int l = 0; l <= val; l++){
hist_sum += hist[l];
}
// assign equalized value
Expand Down
2 changes: 1 addition & 1 deletion Question_21_30/answers_cpp/answer_26.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cv::Mat bilinear(cv::Mat img, double rx, double ry){
val = (1. - dx) * (1. - dy) * img.at<cv::Vec3b>(y_before, x_before)[c] +
dx * (1. - dy) * img.at<cv::Vec3b>(y_before, x_before + 1)[c] +
(1. - dx) * dy * img.at<cv::Vec3b>(y_before + 1, x_before)[c] +
dx * dy * img.at<cv::Vec3b>(y_before + 1, x_before)[c];
dx * dy * img.at<cv::Vec3b>(y_before + 1, x_before + 1)[c];

// assign pixel to new position
out.at<cv::Vec3b>(y, x)[c] = (uchar)val;
Expand Down