Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:45:23+00:00 2026-06-17T09:45:23+00:00

I was trying to sharpening on some standard image from Gonzalez books. Below are

  • 0

I was trying to sharpening on some standard image from Gonzalez books. Below are some code that I have tried but it doesn’t get closer to the results of the sharpened image.

cvSmooth(grayImg, grayImg, CV_GAUSSIAN, 3, 0, 0, 0);

IplImage* laplaceImg = cvCreateImage(cvGetSize(oriImg), IPL_DEPTH_16S, 1);

IplImage* abs_laplaceImg = cvCreateImage(cvGetSize(oriImg), IPL_DEPTH_8U, 1);

cvLaplace(grayImg, laplaceImg, 3);

cvConvertScaleAbs(laplaceImg, abs_laplaceImg, 1, 0);

IplImage* dstImg = cvCreateImage(cvGetSize(oriImg), IPL_DEPTH_8U, 1);
cvAdd(abs_laplaceImg, grayImg, dstImg, NULL); 

Before Sharpening Before Sharpening

My Sharpening Result My Sharpening Result

Desired Result Desired Result

Absolute Laplace Absolute Laplace

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:45:24+00:00Added an answer on June 17, 2026 at 9:45 am

    I think the problem is that you are blurring the image before take the 2nd derivate.

    Here is the working code with the C++ API (I’m using Opencv 2.4.3). I tried also with MATLAB and the result is the same.

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    
    #include <iostream>
    
    using namespace cv;
    using namespace std;
    
    
    int main(int /*argc*/, char** /*argv*/) {
    
        Mat img, imgLaplacian, imgResult;
    
        //------------------------------------------------------------------------------------------- test, first of all
        // now do it by hand
        img = (Mat_<uchar>(4,4) << 0,1,2,3,4,5,6,7,8,9,0,11,12,13,14,15); 
    
        // first, the good result
        Laplacian(img, imgLaplacian, CV_8UC1);
        cout << "let opencv do it" << endl;
        cout << imgLaplacian << endl;
    
        Mat kernel = (Mat_<float>(3,3) << 
            0,  1, 0,
            1, -4, 1,
            0,  1, 0); 
        int window_size = 3;
    
        // now, reaaallly by hand
        // note that, for avoiding padding, the result image will be smaller than the original one.
        Mat frame, frame32;
        Rect roi;
        imgLaplacian = Mat::zeros(img.size(), CV_32F);
        for(int y=0; y<img.rows-window_size/2-1; y++) {
            for(int x=0; x<img.cols-window_size/2-1; x++) {
                roi = Rect(x,y, window_size, window_size);
                frame = img(roi);
                frame.convertTo(frame, CV_32F);
                frame = frame.mul(kernel);
                float v = sum(frame)[0];
                imgLaplacian.at<float>(y,x) = v;
            }
        }
        imgLaplacian.convertTo(imgLaplacian, CV_8U);
        cout << "dudee" << imgLaplacian << endl;
    
        // a little bit less "by hand"..
        // using cv::filter2D
        filter2D(img, imgLaplacian, -1, kernel);
        cout << imgLaplacian << endl;
    
    
        //------------------------------------------------------------------------------------------- real stuffs now
        img = imread("moon.jpg", 0); // load grayscale image
    
        // ok, now try different kernel
        kernel = (Mat_<float>(3,3) << 
            1,  1, 1,
            1, -8, 1,
            1,  1, 1); // another approximation of second derivate, more stronger
    
        // do the laplacian filtering as it is
        // well, we need to convert everything in something more deeper then CV_8U
        // because the kernel has some negative values, 
        // and we can expect in general to have a Laplacian image with negative values
        // BUT a 8bits unsigned int (the one we are working with) can contain values from 0 to 255
        // so the possible negative number will be truncated
        filter2D(img, imgLaplacian, CV_32F, kernel);
        img.convertTo(img, CV_32F);
        imgResult = img - imgLaplacian;
    
        // convert back to 8bits gray scale
        imgResult.convertTo(imgResult, CV_8U);
        imgLaplacian.convertTo(imgLaplacian, CV_8U);
    
        namedWindow("laplacian", CV_WINDOW_AUTOSIZE);
        imshow( "laplacian", imgLaplacian );
    
        namedWindow("result", CV_WINDOW_AUTOSIZE);
        imshow( "result", imgResult );
    
        while( true ) {
            char c = (char)waitKey(10);
            if( c == 27 ) { break; }
        }
    
        return 0;
    }
    

    Have fun!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send out some sms messages via php, using twilio, that have
Trying to parse time from string, but get this error. Tried few formatting string.
Trying to loop thru a result that has items. Items have a type and
Trying to select unique years from timestamp column in a table but so far
trying to get my first HTML/CSS uni assignment sorted but have become a bit
trying to get some info from my Mysql database to show up by connecting
trying out upgrading antlr4, I have 2 lines in the grammar that produce the
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to copy the msdn refernce here doesn't work and gives an error I
trying to figure out why this is happening - I have an input text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.