How to Crop the detected image
1 view (last 30 days)
Show older comments
I am following the object detection from this link: http://www.mathworks.com/help/vision/examples/object-detection-in-a-cluttered-scene-using-point-feature-matching.html#btt5qyu
Is there any way to crop only the box? Or I want to make the image black or white except the box. ex)
Please give me some tip! Thank you!
0 Comments
Answers (1)
Image Analyst
on 5 Dec 2014
It already is black around the image. Do you want it white? If it's a gray scale image you can do it roughly using
grayImage(grayImage==0) = 255; % May not be perfect
though that could turn black pixels inside the box white also. There is a more robust way to get a perfect rectangle using imfill() and regionprops(). Let me know if you need that. Otherwise see the FAQ:
4 Comments
Sufyan Salim
on 15 Mar 2018
Edited: Sufyan Salim
on 15 Mar 2018
I am using the same algorithm though i want it to automatically crop the detected box object in the end and save it as a new image.... how do i do it?
Image Analyst
on 15 Mar 2018
You can use your mask to find the corners:
[rows, columns] = find(mask);
croppedImage = grayImage(rows(1):rows(end), columns(1):columns(end), :);
imwrite(croppedImage, filename);
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!