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

Centroid Function: Inconsistency in Variable Convention and Output Format #3

Open
kamil-janusz-kalinowski opened this issue Apr 18, 2024 · 1 comment

Comments

@kamil-janusz-kalinowski
Copy link

kamil-janusz-kalinowski commented Apr 18, 2024

In the centroid function, there is a swap of the X and Y variables in both the input and output. Although the fragment "Centroid works on column major order" is present, it does not explicitly state that this function returns positions in the format [Y, X]. Especially considering that all code in centroid.m suggests it follows the convention [X, Y]. This change in convention also complicates swapping the centroid method with others, as other methods typically use the convention [X, Y], thus reducing the code's flexibility. To rectify this and provide clarity:

[w, h] = size(im); -> [h, w] = size(im);
Size returns length of dimensions in order Y, X, Z...

[yy, xx] = meshgrid(1:h, 1:w); -> [xx, yy] = meshgrid(1:w, 1:h);
Meshgrid input and output is [X,Y] = meshgrid(x,y)(https://se.mathworks.com/help/matlab/ref/meshgrid.html#d126e1020611)

In the function outside of centroid in shwfs_make_fine_grid.m, there is a change:

dd = shstruct.centroid(subimage, level);
centres(i, :) = [cc(1)+dd(2)-1, cc(3)+dd(1)-1];
It is swap of x and y from dd. dd(1) = X and dd(2) = Y, so it is counterintuitive to add cc(1)+dd(2) (X+Y) and cc(2)+dd(1) (Y+X).
After changes in centroid.m it should be:
centres(i, :) = [cc(1)+dd(1)-1, cc(3)+dd(2)-1];

image
Zrzut ekranu 2024-04-18 150725

@jacopoantonello
Copy link
Owner

Hi. I agree with you that centroid.m uses misleading names. But if its output is changed a lot of other functions should be double checked, not only shwfs_make_fine_grid.m. Possibly the plotting and estimation functions should be revised as well. Despite the wrong names within centroid.m, the code is correct. Currently, it estimates horizontal slopes as a horizontal Zernike tilt and it plots the displacements (quiver) in the right direction. I'll leave this open but currently I don't have time to prepare a thorough revision.

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

2 participants