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

Add hessian-laplace detector #1414

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

warmspringwinds
Copy link
Contributor

Hessian Laplace blob detector efficient implementation.

@@ -151,3 +151,91 @@ def _hessian_matrix_det(cnp.double_t[:, ::1] img, double sigma):
out[r, c] = (dxx * dyy - 0.81 * (dxy * dxy))

return out

def _hessian_matrix_det_and_laplacian(cnp.double_t[:, ::1] img, double sigma):
"""Computes the approximate Hessian Determinant over an image
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a single, first line as a short description.

@warmspringwinds
Copy link
Contributor Author

Basically, this method is very similar to usual Hessian.
But on the coins data is shows better results. (examples are taken from source code examples)
Hessian:
hessian

Hessian-Laplace:
hessian-laplace

But it still has the problem with detecting small blobs as hessian detector:

hessian_stars
hessian_laplace_stars

# This points will be checked for Laplacian scal local maximum
list_of_peaks = []

for scale_number, current_hessian_image in enumerate(hessian_images):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @warmspringwinds
I don't think you need to compute spatial maximas for each scale. From what I understand, you compute the global maximas over the image cube, and ignore the scale component which is later computed by scale space maximas for only the spacial maximas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, @vighneshbirodkar

Thank you for your review 👍

I once implemented a Harris-Laplace.
It is really similar to Hessian-Laplace, but you use Harris measure for finding local maximas
on each scale.
Here is a popular matlab's code for it:
http://www.mathworks.com/matlabcentral/fileexchange/17894-keypoint-extraction/content//keypointExtraction/kp_harrislaplace.m
You can see that they do it for each scale and then test selected points for local maxima in
Laplacian scale space.
And on the wikipedia's page it's said the same:
http://en.wikipedia.org/wiki/Blob_detection#The_Laplacian_of_Gaussian

Did I get your question right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you did.
I think you can replace this for loop with a single call to peak_local_max with footprint as

fp = np.zeros((3,3,3))
fp[:,:,1] = 1

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 92.73% when pulling 1acbcb0 on warmspringwinds:hessian-laplace-blob-detector into d21b6b8 on scikit-image:master.

@@ -159,3 +159,73 @@ def peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1,
nd_indices = tuple(coordinates.T)
out[nd_indices] = True
return out


def get_scale_local_maximas(cube_coordinates, laplacian_cube):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be sped up by a Cython implementation since a majority of it's work is looping through numbers.
You can also argue that in case of _prune_blobs ( which I wrote myself )

Edit : I had adapted it from Alex Donath's code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some research and decided to vectorize this function instead.
I also rewrote this function in Cython, but the vectorized version works faster.
This is the related SO quetion:
http://stackoverflow.com/questions/29155745/speed-up-function-using-cython
All credits go to the author of that answer that vectorized this function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cython can be tricky to fully optimize, but is usually worth the effort for massive memory savings. If you wanted to share that via a Gist, we could see if the potential exists for further efficiency gains.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JDWarner,

https://gist.github.com/warmspringwinds/1aa093ddc6f5b5ed48a6

You can see the benchmarks there.
I will be really glad if you help me.

But I think that the function is called only once in my method and won't speed up the whole script really much if we improve it further.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 92.74% when pulling 826189d on warmspringwinds:hessian-laplace-blob-detector into d21b6b8 on scikit-image:master.

@warmspringwinds
Copy link
Contributor Author

Dear community.
Could you, please, give me a hint on what to do next.
Because later I won't have much time and I am afraid that I won't be able to finish it.

@vighneshbirodkar
Copy link
Contributor

@warmspringwinds An example in doc/examples would help.

The Hessian-Laplace method sometimes gives better results than the method
based on the determinant of Hessian. For example, on the test coin data
Hessian-Laplace shows better results compared to determinant of Hessian.
(the last method has one false positive while Hessian-Laplace doesn't)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clarify last

@warmspringwinds
Copy link
Contributor Author

@vighneshbirodkar I made a thorough research and found out that Hessian-Laplace method
actually works worse than a usual method based on Determinant of Hessian.

This is because determinant of Hessian is better for scale selection as stated here:
http://link.springer.com/article/10.1007/s10851-012-0378-3/fulltext.html
You can read it in summary.

And the example with coins that I showed previously is actually is only a consequence of that fact
that Hessian-Laplace detects only bright blobs on a dark background.

And as it stated in a link that I provided above: Hessian method has
"significantly better repeatability properties under affine or perspective image transformations than the Laplacian". This is important if descriptors are later applied to these points and
matching algoritms are used to find similar points on different images
of the same scene. This blob detection method is, therefore,
is worse than Determinant of Hessian blob detection method.

All the documentation and code comments now represent my findings.

@warmspringwinds
Copy link
Contributor Author

Basically this method is not so useless.
It can be, for example, used in case when the user wants to find only bright blobs
with the speed and accuracy (more or less) of Determinant of Hessian method.
Like in the example with coins (white blobs).

@vighneshbirodkar
Copy link
Contributor

@warmspringwinds The amount of work you put in investigating is certainly appreciated. Your extra notes will certainly be appreciated.

Edit: You implementation also seems fine, why is travis complaining ?

@warmspringwinds
Copy link
Contributor Author

@vighneshbirodkar there is some problem with flake8. A lot of recent pull requests have it.
I opened an issue.

@warmspringwinds
Copy link
Contributor Author

@vighneshbirodkar it is a current issue that prevents travis checks to pass.
#1458

@warmspringwinds
Copy link
Contributor Author

@vighneshbirodkar, now it works after rebase.

@warmspringwinds
Copy link
Contributor Author

@JDWarner, may I ask you to review this PR, so that I am able to correct things?
Because later I might have not enough time.
Thank you.

@soupault soupault changed the title hessian-laplace detector added Add hessian-laplace detector Sep 21, 2016
Base automatically changed from master to main February 18, 2021 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants