liuliu / ccv

C-based/Cached/Core Computer Vision Library, A Modern Computer Vision Library
http://libccv.org
Other
7.08k stars 1.71k forks source link

sobel() result compare with opencv #165

Closed dodoma closed 8 years ago

dodoma commented 8 years ago

hi, Liuliu

Thanks for ccv first.

I have made a test on ccv_sobel().

    ret = ccv_read(data, &mta, CCV_IO_ANY_STREAM | CCV_IO_GRAY, size);
    if (ret != CCV_IO_FINAL) return merr_raise(MERR_ASSERT, "ccv matrix new failure");

    ret = ccv_write(mta, "x.jpg", &size, CCV_IO_JPEG_FILE, NULL);
    if (ret != CCV_IO_FINAL) return merr_raise(MERR_ASSERT, "write matrix failure");

    ccv_sobel(mta, &mtb, CCV_8U | CCV_C1,
              mdf_get_int_value(g_cfg, "ccv.sobel.dx", 0),
              mdf_get_int_value(g_cfg, "ccv.sobel.dy", 0));

    ret = ccv_write(mtb, "pre_result.jpg", NULL, CCV_IO_JPEG_FILE, NULL);
    if (ret != CCV_IO_FINAL) return merr_raise(MERR_ASSERT, "write sobel matrix failure");
int main( int argc, char** argv )
{
    cv::Mat src = cv::imread("x.jpg", 0);
    cv::Mat dst;

    cv::Sobel(src, dst, src.depth(), 0, 1);

    cv::imwrite("z.jpg", dst);

    return 0;
}

I don't know what the window size exact mean. On my raspberry, dx =1, dy = 1 makes best result. Here is the result.

x.jpg, pre_result.jpg, z.jpg

Feel opencv's result more clear, what do you think? Or any suggestion I missed?

gpip commented 8 years ago

It could be related to normalization, for instance using gradient which produces a float matrix and then converting the magnitude matrix via visualize returns a result closer to the one from opencv:

grad_m

Code using https://github.com/gpip/py-ccv:

import sys
from ccv import lib, ccv_read, ccv_write, sobel, gradient, visualize

inp = ccv_read(sys.argv[1])

res = sobel(inp, lib.CCV_8U | lib.CCV_C1)
ccv_write(res, "sobel.jpg")

t, m = gradient(inp)
mo = visualize(m)
ccv_write(mo, 'grad_m.png')
dodoma commented 8 years ago

ok, thanks, i'll try it later.