MATLAB Answers

How can I divide a binary image horizontally?

3 views (last 30 days)
How can I divide a binary image horizontally?


Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 1 Jan 2018
Decide on the column you want to split it at. Then:
leftPart = binaryImage(:, 1:column);
rightPart = binaryImage(:, column+1:end);


Nixon Dhar
Nixon Dhar on 2 Jan 2018
I am working on licenses plate recognition.I want upper and lower part of the I need to divide binary image of the plate horizontally.
Image Analyst
Image Analyst on 2 Jan 2018
I hope you were able to figure out to switch the index, but since you haven't accepted yet, I'll assume not and I'll provide the code below. Assuming you know the top line of the license plate, and the bottom line, and can average those two to get the middle line, simply do this:
upperPart = binaryImage(1:middleRow, :);
lowerPart = binaryImage(middelRow+1:end, :);
Indexing tutorial:
In using indexes, when you say : (colon) by itself, it basically means "all" in whatever index it's at. So above here, it means "all columns" and in my first answer it meant "all rows".
Saying "end" is a shortcut to the last index, without ever having to figure out what it might be. So if binaryImage had 50 rows and 80 columns, binaryImage(20:end, 50:end) would be the lower right part of the image from row 20 to row 50 and column 50 to column 80.
When you use colon with two numbers/expressions on either side, it means go from the left expression to the right expression in steps of 1. So 1:50 would mean a vector [1,2,3,4,5,6,.......,49,50]. When it sees this, MATLAB uses all of those rows. So binaryImage(1:30, :) would mean all columns but only the top 30 rows of the image, whereas binaryImage(:, 60:end) would mean all rows but only from column 60 to the right edge of the image.
I hope that explains indexing and helps you understand and use it in the future.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by