opencv_ex13-彩色轉灰階cvtColor、圖像放大pyrUp、圖像縮小pyrDown、高斯平滑濾波GaussianBlur、圖像相減subtract、圖像歸一化顯示normalize

opencv_ex13-彩色轉灰階cvtColor、圖像放大pyrUp、圖像縮小pyrDown、高斯平滑濾波GaussianBlur、圖像相減subtract、圖像歸一化顯示normalize

opencv_ex13-彩色轉灰階cvtColor、圖像放大pyrUp、圖像縮小pyrDown、高斯平滑濾波GaussianBlur、圖像相減subtract、圖像歸一化顯示normalize



GITHUB:https://github.com/jash-git/CPP_opencv249_ex

    高斯不同(Difference of Gaussian-DOG)
        定義:就是把同一張圖像在不同的參數下做高斯模糊之後的結果相減,得到的輸出圖像。稱為高斯不同(DOG)
        高斯不同是圖像的內在特徵,在灰度圖像增強、角點檢測中經常用到。
    

    心得:對人像而言-DOG可以精準抓抓出圖像邊緣


#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/ml/ml.hpp>

#include <iostream>
#include <cstdio>

#include <sys/timeb.h>
#if defined(WIN32)
    #define  TIMEB    _timeb
    #define  ftime    _ftime
    typedef __int64 TIME_T;
#else
    #define TIMEB timeb
    typedef long long TIME_T;
#endif

using namespace cv;
using namespace std;
Mat src;//input image

void Pause()
{
    printf("Press Enter key to continue...");
    fgetc(stdin);
}
int main()
{
	src = imread("Lena_original.jpg");
	if (!src.data)
    {
		printf("could not load image...\n");
	}
    else
    {
        namedWindow("color_input", CV_WINDOW_AUTOSIZE);
        imshow("color_input", src);

        Mat s_up;
        //放大
        pyrUp(src, s_up, Size(src.cols*2, src.rows * 2));
        imshow("zoom in", s_up);

        //縮小
        Mat s_down;
        pyrDown(src, s_down, Size(src.cols / 2, src.rows / 2));
        imshow("zoom out", s_down);

        //高斯平滑濾波
        Mat gray_src, g1, g2, dogImg;
        cvtColor(s_up, gray_src, CV_BGR2GRAY);
        GaussianBlur(gray_src, g1, Size(5, 5), 0, 0);
        GaussianBlur(g1, g2, Size(5, 5), 0, 0);
        //圖像相減
        subtract(g1, g2, dogImg, Mat());

        //圖像歸一化顯示
        normalize(dogImg, dogImg, 255, 0, NORM_MINMAX);
        imshow("DOG Image", dogImg);
    }
    waitKey(0);
    Pause();
    return 0;
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *