How can I divide a binary image horizontally?

1 visualizzazione (ultimi 30 giorni)
How can I divide a binary image horizontally?

Risposta accettata

Image Analyst
Image Analyst il 1 Gen 2018
Decide on the column you want to split it at. Then:
leftPart = binaryImage(:, 1:column);
rightPart = binaryImage(:, column+1:end);
  3 Commenti
Image Analyst
Image Analyst il 2 Gen 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by