MATLAB: How to crop a interest part image

image segmentationlpr

hellow
I have this image i segmented by kmeans méthod, and i get this résult
Now i want to crop it to get just the license plate
, so there is a solution ???
please help me .

Best Answer

Just get profiles and use find:
verticalProfile = sum(binaryImage, 2); % Sum along columns in each row.
row1 = find(verticalProfile, 1, 'first');
row2 = find(verticalProfile, 1, 'last');
horizontalProfile = sum(binaryImage, 1); % Sum along rows in each column.
column1 = find(horizontalProfile, 1, 'first');
column2 = find(horizontalProfile, 1, 'last');
croppedImage = binaryImage(row1:row2, column1:column2);