Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image.laplacian() non-standard? #216

Open
askerlee opened this issue Apr 3, 2017 · 1 comment
Open

image.laplacian() non-standard? #216

askerlee opened this issue Apr 3, 2017 · 1 comment

Comments

@askerlee
Copy link

askerlee commented Apr 3, 2017

The function image.laplacian() seems to return very different results from what Matlab's fspecial() does.
For example, when size=5, sigma=0.5:
image.laplacian() produces:
0.1898 0.4022 0.4938 0.4022 0.1898
0.4022 0.7158 0.8493 0.7158 0.4022
0.4938 0.8493 1.0000 0.8493 0.4938
0.4022 0.7158 0.8493 0.7158 0.4022
0.1898 0.4022 0.4938 0.4022 0.1898
Whereas fspecial('log') produces:
-0.0091 -0.0095 -0.0115 -0.0095 -0.0091
-0.0095 -0.0646 -0.1457 -0.0646 -0.0095
-0.0115 -0.1457 1.0000 -0.1457 -0.0115
-0.0095 -0.0646 -0.1457 -0.0646 -0.0095
-0.0091 -0.0095 -0.0115 -0.0095 -0.0091
Both filters are normalized by the central [3,3] element.
I've tried a few other parameter values and none of them are the same. Moreover, image.laplacian() seems to contain many more positive numbers.

I'm not an image processing person so am not sure if I misunderstood the documentation of this API. Thank you for any help.

@askerlee
Copy link
Author

askerlee commented Apr 3, 2017

I've found a suspicious line in init.lua:

         local xsq = math.pow((i-center_x)/(sigma_horz*width),2)/2
         local ysq = math.pow((j-center_y)/(sigma_vert*height),2)/2

In the standard equation (http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm), sigma_horz and sigma_vert are not multiplied by width (height). Is this a bug?

After removing this scaling factor and normalizing the matrix to sum to 0, I got identical results as Matlab. The complete code snippet is:

local logauss = torch.Tensor(height,width)
for i=1,height do
       for j=1,width do
           xsq = math.pow((i-center_x)/sigma_horz,2)/2
           ysq = math.pow((j-center_y)/sigma_vert,2)/2
           derivCoef = 1 - (xsq + ysq)
           logauss[i][j] = derivCoef * math.exp(-(xsq + ysq))
       end
end
logauss = logauss -  logauss:sum() / (height*width)
logauss = logauss / logauss[ { math.floor(center_x), math.floor(center_y) } ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant