-
-
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
skimage.segmentation.quickshift signature is missing from API docs #2017
Conversation
That's interesting:
|
@@ -14,7 +14,7 @@ from ..util import img_as_float | |||
from ..color import rgb2lab | |||
|
|||
|
|||
def quickshift(image, ratio=1., float kernel_size=5, max_dist=10, | |||
def quickshift(image, ratio=1.0, kernel_size=5, max_dist=10, |
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.
kernel_size
is used in a nested for-loop in this function. It seems like we should precompute the value used in that loop and store it.
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.
(as a cdef
)
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, already working on that.
@soupault, that error makes sense given my comments above. |
@@ -112,7 +113,7 @@ def quickshift(image, ratio=1.0, kernel_size=5, max_dist=10, | |||
dist += (current_pixel_p[channel] - | |||
image_c[r_, c_, channel])**2 | |||
dist += (r - r_)**2 + (c - c_)**2 | |||
densities[r, c] += exp(-dist / (2 * kernel_size**2)) | |||
densities[r, c] += exp(-dist / (2 * kernel_size_c**2)) |
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.
How about cdef float kernel_size_sq = kernel_size**2
instead (it was a float before, and this saves taking the square each time).
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, sorry, you are 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.
I am fairly certain that the compiler is smart to optimize, but why not go all the way and make it inv_neg_kernel_size_sqr = -0.5 / kernel_size**2
? The loss in precision shouldn't matter too much in this case I assume.
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.
@ahojnnes I fully agree, but, in my opinion, this should be an another PR. One can find other things (incl. TODO ⚡) which should be addressed.
LGTM |
cdef int kernel_size_c = kernel_size | ||
cdef int w = 3 * kernel_size_c | ||
cdef float kernel_size_sq = kernel_size**2 | ||
cdef int w = int(3 * kernel_size) |
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.
hm, maybe ceil?
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.
True that.
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.
@ahojnnes Should I use cnp.ceil
or np.ceil
here?
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.
Won't matter too much, but cnp.ceil should be a wrapper around the ceil function in <math.h>
and therefore faster in Cython 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.
Ok, clear. I've already made the change.
7b8a677
to
85b7f6b
Compare
THanks @soupault! |
skimage.segmentation.quickshift signature is missing from API docs
Should fix #2005 .