I have a python function that takes a list of smaller images boxes (represented as float arrays) and the whole image img in as a parameter and finds outliers. The outliers will either be significantly brighter or darker than the other images in the list, but darker is the more common case.

def find_outliers(boxes, img):
    means = [np.mean(box['src']) for box in boxes]
    asc = sorted(means)
    q1, q3 = np.percentile(asc, [25,75])
    iqr = q3 - q1
    lower = q1 - (1.5 * iqr)
    upper =  q3 + (1.5 * iqr)

    # print('thresholds:', lower, upper)
    return list(filter(lambda x: np.mean(x['src']) < lower or np.mean(x['src']) > upper, boxes))

This method allows me to create thresholds based on the image, instead of coming up with hard values, which is ideal in my situation. There are 3 problems I need to address if I continue this approach.

  1. Sometimes the brighter/darker images outnumber the normal images. These images have extreme values which biases my outlier method into thinking they are normal.
  2. Sometimes the number of boxes is very small (3 or 4). This makes it hard for this method to find a lower and upper bound.
  3. The lower and upper bounds can be negative, but all of my values will be greater than or equal to 0

Is there a statistical approach that is better suited for this type of problem?

Note: I also have tried the standard deviation outlier approach but this one isn't suitable in this scenario.


1 Answer 1


You seem to have two conflicting criteria in mind for what it means to be a light or dark outlier: (a) 'light' or 'dark' compared with the current group, (b) 'light' or 'dark' according to a personal judgment of what those words mean.

For example, in your first item: Lots of dark images in a group set a standard for 'dark' that is too low for your personal judgment. And in your second item: there are not enough images in the group to set reasonable standards for the group.

To an extent, you might be able to have it both ways. Perhaps look at many groups merged together and see what boundaries for 'dark' and 'light' the boxplot method sets. You might change the factor 1.5 in 1.5*iqr to be larger or smaller so that the boxplot boundaries for the many groups taken together don't offend your personal judgment. There is no reason the multiplier for 'light' on the high side or for 'dark' on the low side need to be the same. For example, you might find it is good to use 1.2 on the low side and 2.0 on the high side.

Then look at some smaller groups using the new factors to see if you think the revised outlier rules are working well. Finally, decide on some arbitrary override (postive) bound to use in case the revised boxplot lower bound is negative for a particular group.

As for item 1, it may make sense to judge 'light' and 'dark' in the context of a particular group---especially if individual images will usually be displayed along with other images in their own group.

In this regard, it may be worthwhile looking at boxplot outliers (1.5IQR rule) for 20 groups all from the same normal distribution. Notice that what are judged high or low outliers can differ greatly from one group to another.

enter image description here

Some groups happen to declare anything above 90 as 'bright' while others find no bright items in a group that has images as high as 100. In one group, 40 was declared dark, in others, 30 isn't considered dark. Each group has 70 images and altogether there are 1400--all from the same population distribution.

Everything considered together, maybe it would be a good idea to declare 100 as the upper boundary and 40 as the lower. Very roughly, those are the values that cut off about the lowest 2% and highest 2% of the observations.

I haven't seen any of your images. I'm not trying to persuade you to use any one particular method or criterion. Just trying to get you to think of alternatives that might work.

  • $\begingroup$ Yes! Those two ideas are equally important. A dark box could represent dark box compared to the other boxes, or a dark box relative to the image itself. Here it gets tricky because in some cases darker doesn't necessarily make it an outlier. So as long as the other boxes are within range they should be normal values.... but there is some sort of absolute upper and lower value which should be taken into account, depending on the image. This is something I have to be careful with because I want to avoid as many false positives as possible. $\endgroup$ Commented Aug 2, 2019 at 14:02
  • $\begingroup$ Is there another outlier detection method which you think might be more effective? $\endgroup$ Commented Aug 3, 2019 at 0:54
  • 1
    $\begingroup$ There are several, but some tailor-made modification of the boxplot outlier criterion is probably best for your purposes. // One possible alternative, which is a little more tedious to program: Leave out the first observation in a sample of $n>30,$ compute the mean $\bar X_{[1]}$ and SD $S_{[1]},$ then see if $X_1$ is in the interval $\bar X_{[1]} \pm 2S_{[1]}\sqrt{1+1/n}.$ If not, then $X_1$ is an outlier. Repeat similarly to see if $X_2$ is in $\bar X_{[2]} \pm 2S_{[2]}\sqrt{1+1/n},$ and so on. $\endgroup$
    – BruceET
    Commented Aug 3, 2019 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.