Runtime warning with blob detection when threshold is too low

Dear community,

I’m struggling to understand why the errors in the blob detection occur which are also shown at the official scikit-image documentation page. I also have the same issue where Python tells me that it’s dividing by 0 when I run my code which is shown below (here ist the link to the image I’m using: stars4.jpg). When I set the threshold to 0.8, it doesn’t spit out the same warning messages.

import numpy as np
from import imread 
from skimage.color import rgb2gray
from skimage.feature import blob_log

stars = imread('data/stars1.jpg', as_gray=True)
blobs_log = blob_log(stars, max_sigma=30, threshold=.03)
numrows = len(blobs_log)
print('There are {} stars!'.format(numrows))

I’ve tried to read the which is apparently giving out the runtime error message and didn’t understand the issue to its full extent. Can someone help me out or point me into the right direction with this?

This looks like a bug in the way overlaps are handled by the function. Basically, if it finds two overlapping blobs, it sets the widths of one of them to zero to suppress it. However, if that suppressed blob overlaps with a third one, the function has to do somewhere a division operation with this width set to zero which generates the “division by zeros” warning. It looks like it doesn’t affect the end result though. Your problem disappears with a higher intensity threshold because this just suppresses overlap cases (in particular in the lower part of your image which has high background). I’ll try to post an issue on GitHub about this.

Hello guiwitz! Thanks a ton for answering. I’ve tried to look up what exactly happens in (which is called by blob_log) and it seems that it happens during pruning to, as you’ve said, get rid of the overlapping blobs. However, I still have trouble understanding the threshold value. In OpenCV there seems to be two thresholds: a minimum threshold and a maximum threhsold. Also, if, let’s say I’m chosing a min sigma of 0.5 and a max sigma of 1.5 - what exactly does that mean? Does skimage iterate over multiple versions of sigmas to determine the blobs? If so, why can I not set a step size?

Sorry to bother you with all those questions which you probably can’t address since you didn’t write the function. Also thanks for helping me :slight_smile:

I think you are mixing up intensity threshold and sigma threshold. The blob detector indeed uses a series of LoG filters of different widths to detect blobs of different sizes. The size of those filters ranges from min_sigma to max_sigma, and you can also set num_sigma to fix the step size. The threshold option allows you to suppress blobs with intensities below a certain threshold, to avoid picking up tiny fluctuations due to noise. Just FYI the scikit-image is documented quite extensively. In this case you can just read about what each parameter is doing here:


Welcome to the forum @randomluck and thank you very much for the help @guiwitz! I’ve created an issue in the scikit-image repo so that we can remove the warning. As @guiwitz was saying the division by zero should not impact the result because the two terms are zero.

1 Like