This question has originally been posted on the math stack exchange, but these guys redirected me to you.

Find it at https://math.stackexchange.com/questions/566065/exclude-an-rgb-color-from-a-set

-- Here's the question again --

I'm currently implementing an algorithm to split an image into smaller chunks, based on straight line separators.

Here's the image I'm processing. It's very small, so you may want to save it and enlarge.

The sample image with three zones

If you look at this image, you can clearly see 3 different zones. But because I used JPG compression, the separator lines have variable pixel colours.

With the adequate colour difference threshold, it's easy to find these separators (although probably not the best way, now that I rethink about it). Here below are 10 identified separators, or more specifically the average RGB colour of the pixels they contain.

# the three big horizontal separators
row 1 : (64, 43, 32)
row 5 : (60, 46, 29)
row 10: (53, 46, 46)

# now if you use these horizontal lines to split the image,
# you still have two images (do not include the horiz. separators)

# the top one contains three vertical separators
col 1 : (54, 45, 42)
col 8 : (152, 124, 81)
col 10: (43, 49, 43)

# and the bottom contains four
col 1 : (53, 48, 36)
col 5 : (53, 50, 30)
col 6 : (52, 46, 32)
col 10: (43, 52, 45)

As we can see, one of these color average stands out. And as you may see on the picture, it's not really a separator, but only a column of three pixels alike.

I need to discard this fake separator from the set, but I'm having a rough time figuring out an algorithm for this. Initially I'd base this on a standard deviation, removing the ones that are too far away. I don't want to do an average here, as there could be few separators in some cases, and it may lead to false positives.

But I'm lacking mathematical education here. How can I do that on vectors, can anyone provide a working (or better) solution?

  • $\begingroup$ Will all the separators always be approximately the same color? Also, will the separators always be connected to each other? $\endgroup$ – Flask Nov 14 '13 at 9:42
  • $\begingroup$ Yes, the separators are expected to have the same color (modulo the jpeg compression). And yes, they will be connected to each other, meaning that each sub-image is a closed rectangle. However, there may be no border around the image, nor do I know where a separator starts. $\endgroup$ – Antoine_935 Nov 14 '13 at 9:46
  • $\begingroup$ Two more question, I think I have a past solution I can share. If the separators were all one color would you expect this to be the largest contiguous clump of color? Would you expect the separator color to be the most common color in the image? $\endgroup$ – Flask Nov 14 '13 at 9:50
  • $\begingroup$ It is very likely, but the other colors may be close. One of the target images is 24.media.tumblr.com/7d152fc9d14e12bcc5cf3b31fde4a438/… I'd be very interested in seeing your solution anyway :) More sample images here: howtotheapp.tumblr.com $\endgroup$ – Antoine_935 Nov 14 '13 at 10:09
  • $\begingroup$ I keep thinking of things that can go wrong with my original idea, but I have a new one. Can you give code for exactly how you detected the separators? $\endgroup$ – Flask Nov 14 '13 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.