laplace-image sharpening [closed]

asked 2013-10-11 06:17:42 -0600

GiulSDU gravatar image

updated 2013-10-11 06:45:39 -0600

berak gravatar image

Hi, i need to sharp an image. Trying to use Lapacian filter but get the same figure as output. Can t find the error in the code

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>

using namespace cv;
using namespace std;
float laplacian(Mat image,int x,int y)
{

    float sum=0;
    float value=0;
    for(int j = x-1; j <= x+ 1; j++)
    {
        uchar* data = image.ptr<uchar>(j);
        for(int i = y-1; i <= y+1; i++)
        {
            if (j==x && i==y)
            {
                value=data[i]*(-8);
            }

            else value=data[i];

         sum=sum+value;

        }
    }

return sum;
}
Mat paddImage(Mat image,int size,int borderType)
{
Mat padded;
int top, bottom, left, right;
Scalar value;


top = size; bottom = size;
left = size; right = size;


copyMakeBorder( image, padded, top, bottom, left, right, borderType);

return padded;
}


int main( int argc, char** argv )
{


    if( argc != 2)
    {
        cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }

    Mat blurred;

    blurred=imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE );

    namedWindow("blurred", CV_WINDOW_AUTOSIZE );
    imshow("blurred", blurred );

      Mat padded=paddImage(blurred,1,BORDER_CONSTANT);
        namedWindow("blurred pad", CV_WINDOW_AUTOSIZE );
        imshow("blurred pad", padded );



            for(int j = 1; j < padded.rows-1; j++)
                        {
                            uchar* data = padded.ptr<uchar>(j);
                            for(int i = 1; i < padded.cols-1; i++)
                            {

                                data[i]=data[i]-((-1/9)*laplacian(padded,j,i))*data[i];

                            }
                        }


            namedWindow("sharpen", CV_WINDOW_AUTOSIZE );
            imshow("sharpen", padded );

    waitKey(0);
    return 0;
}
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-27 08:00:57.209331

Comments

it probably won't help much, but :

data[i]=data[i]-((-1/9)*laplacian(padded,j,i))*data[i];

(-1/9) should be (-1.0/9.0), the int version degrades to 0 !

berak gravatar imageberak ( 2013-10-11 06:47:56 -0600 )edit

Shouldnt this solve it? I mean, currently he is basically doing data[i] = data[i], since the rest is 0.

Moster gravatar imageMoster ( 2013-10-11 07:05:56 -0600 )edit

but it doesn't.i just get a picture with random white and black pixel

GiulSDU gravatar imageGiulSDU ( 2013-10-11 09:04:41 -0600 )edit

what, if you just stop reinventing the wheel, and use the builtin laplacian ?

berak gravatar imageberak ( 2013-10-11 09:11:47 -0600 )edit

would be great but laplacian function seems difficult as well

GiulSDU gravatar imageGiulSDU ( 2013-10-11 09:27:07 -0600 )edit