1

Given a connected component such as this:

enter image description here

I'd like to slice the image into two images where the narrowest part appears, so the output would look like this:

enter image description here, enter image description here

note: I have added few more examples (as requested):.

1)enter image description here

enter image description here enter image description here

2)enter image description here result with: enter image description here, enter image description here,

JammingThebBits
  • 732
  • 11
  • 31
  • 1
    Vertical projection histogram. For each column, sum 1 for white pixels, and 0 for black pixels. You'll find that the "narrowest" part has a value > 0, but lower than the bigger parts – Miki Aug 13 '18 at 10:37
  • 1
    @Miki This would only work for the shown example, but if you rotate the image by 90 degrees it will fail. JammingThebBits: Are you looking for a general solution or just for a solution for the given image? – NewTech Aug 13 '18 at 13:33
  • @New yes I know, that's what the question is asking (right now). – Miki Aug 13 '18 at 13:37
  • I agree with @NewTech i'm looking for a more general solution both to rotated image. – JammingThebBits Aug 13 '18 at 15:56
  • Thank you @Miki for the suggestion, sorry for not explaining myself in depth. – JammingThebBits Aug 13 '18 at 15:56
  • 2
    The white blob shape is always like this? If so, you can simply make it "horizontal" (`minAreaRect` and rotate), and use the the vertical projection as explained before. Otherwise, please post some test cases that cover all the possibilities you can have – Miki Aug 13 '18 at 16:04
  • You didn't answer @Miki ... is the white shape always the same one? – Mark Setchell Aug 13 '18 at 21:14
  • @Miki the shape is randomly generated, i have updated the original question. I thought of approaching this question as a binary-search question, apply the function erode until I get two distinct connected component. then I can estimate where the should I conduct the split on the original image. – JammingThebBits Aug 13 '18 at 21:47
  • 1
    Please show some other shapes then so we know what we are dealing with. – Mark Setchell Aug 13 '18 at 21:58
  • Your new shape makes your question vastly different. I think you need to show more shapes and what the expected results are because I have no idea what you are doing now! Sorry. – Mark Setchell Aug 14 '18 at 07:35
  • @Mark Ok, so I have added few more examples and removed the original example. – JammingThebBits Aug 14 '18 at 14:10

1 Answers1

2

A really general and quite robust approach would be using erosion and watershed transformation:

  1. Erode the binary image with a square kernel of size k
  2. Check for the number of components. If the number of components < 2 set k = k + 1 and repeat from step 1.

This will eventually result in 2 (or more) separated components. Now:

  1. Calculate markers for the watershed transformation using the components as labels you received in the previous step.
  2. Perform a marker-based watershed transformation with your markers and obtain your different components including the borders for each component.

For a code reference, you may want to take a look at this watershed segmentation guide from OpenCV. They have a use case quite similar to your own application.

T A
  • 1,677
  • 4
  • 21
  • 29
  • 2
    “quadratic kernel” sounds a bit like you mean a parabolic kernel. I think you mean square? This is a good approach, but why watershed? What is the grey-level image to use? – Cris Luengo Aug 14 '18 at 21:01
  • You're right, I will change it to "square" to avoid further confusion. Watershed will naturally find the borders between the two components. I have found it useful to separate components whose borders are not clearly defined. The grey-level image will consist of the different components found prior by the CC algorithm, as well as the eroded foreground, which will be set to "unknown" so the WST can do its work. Thanks for the feedback, I will add this the answer if this clarifies the approach. – T A Aug 16 '18 at 06:52
  • 1
    @T A thank you for elaborating (thumb up), i'll be trying it for sure during the weekend :) so i'll update soon! – JammingThebBits Aug 17 '18 at 20:48