Ask Your Question
0

How to implement classical hybrid image with opencv

asked 2017-12-24 10:18:16 -0600

LJZ gravatar image

how to implement classical hybrid image with opencv?

edit retag flag offensive close merge delete

Comments

you mean, this ?

berak gravatar imageberak ( 2017-12-24 11:24:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-12-24 13:56:40 -0600

LBerger gravatar image

updated 2017-12-24 14:07:07 -0600

It's a gift! (with this license)

image descriptionimage from https://github.com/opencv/opencv/wiki...

#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>

using namespace std;
using namespace cv;

struct ParamThresh {
    int highFreq;
    String winName;
    Mat m1,m1f,tfM1f;
    Mat m2,m2f, tfM2f;
    Mat fDist;
};

void AjouteGlissiere(String nomGlissiere, String nomFenetre, int minGlissiere, int maxGlissiere, int valeurDefaut, int *valGlissiere, void(*f)(int, void *), void *r)
{
    createTrackbar(nomGlissiere, nomFenetre, valGlissiere, 1, f, r);
    setTrackbarMin(nomGlissiere, nomFenetre, minGlissiere);
    setTrackbarMax(nomGlissiere, nomFenetre, maxGlissiere);
    setTrackbarPos(nomGlissiere, nomFenetre, valeurDefaut);
}

void ChooseThreshold(int x, void *r)
{
    ParamThresh *pgc = (ParamThresh*)r;
    if (!pgc->m1.empty() && pgc->m1.size() == pgc->m2.size())
    {
        Mat tfR = Mat::zeros(pgc->tfM1f.size(), pgc->tfM1f.type());
        Mat mask = pgc->fDist > pgc->highFreq;
        Mat f = pgc->tfM1f.clone(),res,dst;
        pgc->tfM2f.copyTo(f, mask);
        idft(f, res, cv::DFT_SCALE | DFT_REAL_OUTPUT);
        res.convertTo(dst, CV_8UC1);
        imshow(pgc->winName, dst);
        waitKey(50);
    }
}

int main (int argc,char **argv)
{
        ParamThresh pgc;
        pgc.m1 = imread("g:/lib/opencv/samples/data/apple.jpg", IMREAD_GRAYSCALE);
        pgc.m2 = imread("g:/lib/opencv/samples/data/baboon.jpg", IMREAD_GRAYSCALE);
        pgc.winName = "Hybrid";
        CV_Assert(pgc.m1.size() == pgc.m2.size() && pgc.m1.rows==pgc.m1.cols);
        imshow("original1", pgc.m1);
        imshow("original2", pgc.m2);
        pgc.highFreq =pgc.m1.rows / 2;

        namedWindow(pgc.winName, WINDOW_GUI_EXPANDED);
        AjouteGlissiere("thresh", pgc.winName, 0, pgc.m1.rows/2, pgc.m1.rows /2, &pgc.highFreq, ChooseThreshold, (void*)&pgc);
        waitKey(20);
        pgc.m1.convertTo(pgc.m1f, CV_32F);
        pgc.m2.convertTo(pgc.m2f, CV_32F);
        pgc.fDist = Mat(pgc.m2f.size(), CV_32F);
        for (int i = 0; i<=pgc.fDist.rows / 2; i++)
            for (int j = 0; j <= pgc.fDist.cols / 2; j++)
            {
                float d = sqrt(i*i*1.0 + j * j*1.0);
                pgc.fDist.at<float>(i, j) = d;
                if (i != 0)
                    pgc.fDist.at<float>(pgc.fDist.rows - i, j) = d;
                if (j != 0)
                    pgc.fDist.at<float>(i, pgc.fDist.cols - j) = d;
                if (j != 0 && i != 0)
                    pgc.fDist.at<float>(pgc.fDist.rows - i, pgc.fDist.cols - j) = d;
            }

        dft(pgc.m1f, pgc.tfM1f, cv::DFT_COMPLEX_OUTPUT);
        dft(pgc.m2f, pgc.tfM2f, cv::DFT_COMPLEX_OUTPUT);
        char code = 0;
        while (code != 27)
            code = waitKey(10);

}

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-12-24 10:18:16 -0600

Seen: 701 times

Last updated: Dec 24 '17

Related questions