0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

OpenCVを使ってLenaさんを減色にする

Posted at

Lenaさん画像は256x256x256の16777216色だが、減色して64色にしてみる。
256を64で割ると各色4種類。4x4x4=64色、減色にともなって暗くなるので
ちょっと明るくする加工を少し追加。


//画面をだすよ
void display(cv::Mat image) {
    //名前をつける
    std::string windowName = "windowName";
    cv::namedWindow(windowName);
    //画面位置固定
    cv::moveWindow(windowName,100,100);
    //画面出た!!
    cv::imshow(windowName, image);
    //なにかキーをおして~
    cv::waitKey(0);
    //整理整頓
    cv::destroyWindow(windowName);
}

//
// ここから
//
int main(int argc, char** argv) {

    //lenaさん登場!!
    cv::Mat lena = cv::imread("lena.jpg");
    int cols = lena.cols;
    int rows = lena.rows;

    int reduce = 256 / 4;
    for (int j = 0; j < rows-10; j++) {
        for (int i = 0; i < cols ; i++) {
            for (int k = 0; k < 3 ; k++) {
                image.at<cv::Vec3b>(j, i)[k] =  lena.at<cv::Vec3b>(j, i)[k] / reduce * reduce + reduce/2;
            }
        }
    }

    //画面に出して!!
    display(image);
}

オリジナルLenaさん

f:id:treehitsuji:20150125104314p:plain

減色Lenaさん

f:id:treehitsuji:20150125104327p:plain

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?