-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
base: main
Are you sure you want to change the base?
Add hessian-laplace detector #1414
Conversation
@@ -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 |
There was a problem hiding this comment.
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.
skimage/feature/blob.py
Outdated
# This points will be checked for Laplacian scal local maximum | ||
list_of_peaks = [] | ||
|
||
for scale_number, current_hessian_image in enumerate(hessian_images): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@@ -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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Dear community. |
@warmspringwinds An example in |
skimage/feature/blob.py
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clarify last
@vighneshbirodkar I made a thorough research and found out that Hessian-Laplace method This is because determinant of Hessian is better for scale selection as stated here: And the example with coins that I showed previously is actually is only a consequence of that fact And as it stated in a link that I provided above: Hessian method has All the documentation and code comments now represent my findings. |
Basically this method is not so useless. |
@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 ? |
@vighneshbirodkar there is some problem with flake8. A lot of recent pull requests have it. |
@vighneshbirodkar it is a current issue that prevents travis checks to pass. |
dad76b9
to
637501f
Compare
@vighneshbirodkar, now it works after rebase. |
@JDWarner, may I ask you to review this PR, so that I am able to correct things? |
Hessian Laplace blob detector efficient implementation.