Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I solved it using "add" function to calculate image vertices in x and y axis.Therefore it we are able to combine each thresholded image in x and y direction.even if the area we want to distinguish on the image comes in the x direction, we can get the appropriate photo by combining it with the y direction.

Here is the code :

Mat Morphology::Sobel_operations(Mat& gray_image){//directly change vector with using only struct(future operations)

    vector<Sobel_variables> sobel_variables(1);
    //Sobel_variables sobel_variables;
    sobel_variables[0].alpha = 1;

    sobel_variables[0].beta = 0.9;

    Sobel(gray_image, sobel_variables[0].Gradx, sobel_variables[0].ddepth, 1, 0, 3);
    Sobel(gray_image, sobel_variables[0].Grady, sobel_variables[0].ddepth, 0, 1, 3);

    subtract(sobel_variables[0].Gradx, sobel_variables[0].Grady, sobel_variables[0].Gradient);

    //normalize(sobel_variables[0].Gradient, sobel_variables[0].Gradient, 1, 0, NORM_MINMAX);
    //convertScaleAbs(sobel_variables[0].Gradient, sobel_variables[0].Gradient);


    add(sobel_variables[0].Grady, sobel_variables[0].Gradx, sobel_variables[0].Gradient1);


    //convertScaleAbs(sobel_variables[0].Gradient1, sobel_variables[0].Gradient1);//It can be used but not necessary

    addWeighted(sobel_variables[0].Gradient, sobel_variables[0].alpha, sobel_variables[0].Gradient1, sobel_variables[0].beta, 0, sobel_variables[0].Out_Image);



    imshow("Sobel_operations", sobel_variables[0].Out_Image);

    //------free memory of all unnecessarry images--------------------------
    sobel_variables[0].Gradx.release();
    sobel_variables[0].Grady.release();
    gray_image.release();
    sobel_variables[0].Gradient.release();
    sobel_variables[0].Gradient1.release();

    return sobel_variables[0].Out_Image;

}