how to crop a interest part image

2 views (last 30 days)
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 .

Accepted Answer

Image Analyst
Image Analyst on 11 Apr 2015
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);
  4 Comments
Image Analyst
Image Analyst on 12 Apr 2015
guitone's "Answer" moved here:
Thank you for reply, but there is an error:
Index exceeds matrix dimensions.
Error in test (line 51)
greenChannel = rgbImage(:, :, 2)
Can you help me?
Image Analyst
Image Analyst on 12 Apr 2015
You're obviously not using the image that you posted and gave to me. The image you posted is a color image, but the one you're using is a grayscale image. So you need to put this code after your call to imread():
if numberOfColorBands >= 3
% Crop the image
rgbImage = rgbImage(50:400, 100:600, :);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Crop the image
grayImage = redChannel;
else
% It's already gray scale.
% Crop the image
grayImage = rgbImage(50:400, 100:600, :);
end

Sign in to comment.

More Answers (1)

guitoune mohieddine
guitoune mohieddine on 12 Apr 2015
Edited: guitoune mohieddine on 12 Apr 2015
thank you , it works

Community Treasure Hunt

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

Start Hunting!