Split a binary image into 2 parts by specifying the separation point
4 views (last 30 days)
Show older comments
Ankit Sahay
on 5 Oct 2020
Commented: Ankit Sahay
on 4 Jan 2021
Hi all!
This is a new question based on a previous question I had asked: https://www.mathworks.com/matlabcentral/answers/593500-splitting-a-binary-image-into-2-parts?s_tid=srchtitle
Unfortunately, I had not formulated my earlier question properly, for which I am extremely sorry. I am starting a new question as I have reformulated my problem.
I have a binary image attached:
The corresponding .mat file is also attached.
I want to separate the binary image into 2 parts, with the separation point being the cell having cell value 1 in the top-most row (of the cells having 1 as their cell value). For example, for the above image, I would like to get the following 2 images:
and
The separation point is at [X Y] = [342 60]. Row 60 is the top most row which has cells with cell value 1. Column 342 is the last column on this particular row which has cell value 1. I hope I am satisfactorily able to define the separation point.
Unlike my previous question, I have made sure that there is only one 8-connectivity component. This can be verified by using the command:
cc = bwconncomp(binary_image1,8)
If there are more than one cell having value 1 on the top-most row (of the cells having 1 as their cell value), we can select either the first or the last cells having 1 in that particular row as the separation point. I would love if there is an option to change between the first or last cells, but this is a very important requirement. In that case, we can select the last cell as the separation point, as done in the figures attached above.
I tried the answers given for my previous question, they don't work. I think its obvious, as my question was ill-formulated. I hope this new question can help me.
Please let me know if I can clarify anything else. Thank you.
0 Comments
Accepted Answer
Parth Dethaliya
on 24 Dec 2020
A simple solution to what you have asked could be setting the value of seperation point to 0 then finding connected components again, Now there will be two components because you have broked the connectivity.
Comment here for further clarification if i am not clear.
You can find the top most row containing 1 by,
[r,c] = find(B==1);
min(r)
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!