From 3502d8805ff4a0092f7123de4b87b86195e1845b Mon Sep 17 00:00:00 2001 From: Crazy_snail Date: Tue, 22 Sep 2020 16:09:25 +0800 Subject: [PATCH] Update answer_10.cpp --- Question_01_10/answers_cpp/answer_10.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Question_01_10/answers_cpp/answer_10.cpp b/Question_01_10/answers_cpp/answer_10.cpp index 73b7c170..e0f88ba8 100644 --- a/Question_01_10/answers_cpp/answer_10.cpp +++ b/Question_01_10/answers_cpp/answer_10.cpp @@ -34,7 +34,8 @@ cv::Mat median_filter(cv::Mat img, int kernel_size){ // get neighbor pixels for (int dy = -pad; dy < pad + 1; dy++){ for (int dx = -pad; dx < pad + 1; dx++){ - if (((y + dy) >= 0) && ((x + dx) >= 0)){ + if (((y + dy) >= 0) && ((x + dx) >= 0) && + ((y + dy) < height) && ((x + dx) < width)){ vs[count++] = (int)img.at(y + dy, x + dx)[c]; } }